How Do We Get User Input in Java? - Full Tutorial

preview_player
Показать описание
All about using the Scanner class in Java to get user keyboard input, with examples for a String, int, and float.

Watch this Java lesson to learn how to use the built-in Scanner class to retrieve input from the user!

Learn or improve your Java programming by watching it being coded live in tutorials!

Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for over a decade, and I love teaching what I know.

Tell me what else you want to see!

Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.

📕 THE best book to learn Java, Effective Java by Joshua Bloch

📕 One of my favorite programming books, Clean Code by Robert Martin

🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial

🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)

📹Phone I use for recording:

🎙️Microphone I use (classy, I know):

Donate with PayPal (Thank you so much!)

☕Complete Java course:

Рекомендации по теме
Комментарии
Автор

Thanx so much John! I'm on my third week for Java dev. Yesterday I cried in class, and yelled; I just don't understand anything! Today I'm back up on the horse. My teacher guided me to your chanel. XOXO thai

thaimilamonegabolander
Автор

You are so amazing, Please continue making more videos on Java. Will be greatly appreciated!

ruantristancarlinsky
Автор

Im surprised so many people make videos or go on forums despite how wrong they are most of the time! its really amazing

raphaelferrazza
Автор

It's a veeery good tutorial, thank you!

szaronaangel
Автор

buddy you're doing a great job, i really want to thankyou for this, could you plz make a video about oops but in advance way, but each of the four concept should be explained in the separate video

tushartomar
Автор

Cheese sanwidch is not garbage.
Video is very helpful!

kristinaz
Автор

Love all your videos...
You're truly awesome 👍💪
Please could you do a video on the different types of ways to get user inputs?
Be keeping an eye out for this
✊✊

dypsking
Автор

I would like smaller and easier tutorials like constructor tutorial you made that was pretty good

Arfifias
Автор

In chapter 8 I was taught something called casting (not working with the scanner class). Are both what I mentioned and what you tought us equaly valid or is there a difference?

etipeti
Автор

Great method how to teach
Respect from Afghanistan 🇦🇫…

Ahmadzai-
Автор

So we're just ignoring his shoe size? (Great video)

jeremyunger
Автор

At 6:36, how did you delete the whole line so quickly without selecting the characters ? What is that keyboard shortcut ?

theconsul
Автор

i have a question at around 11:05, I saw you assigned floatAge the value inside of the try block, but declared it outside of it. Is this necessary, or could you declare floatAge and initialize both inside of the try block?

vic.
Автор

I can't make a cheese sandwich into a float, but I can make ice cream into a float by pouring soda on it.

Pacvalham
Автор

How to make the scanner inputs are beside the question??

thariqdeyis
Автор

Can you explain why you can’t reopen a Scanner after you call close?

anyahayes
Автор

Hi John. I have a strange issue. I expect code below to allow me to enter 3 string elements from keyboard but unfortunately after entering two strings, immediately I see the output of myStrings array which looks odd: [FirstString, , SecondString]. There is an empty element between myStrings[0] and myStrings[2]? Why? It is expecting that each scanner.nextLine() will consume the new line including \n; but the situation is not as such?

import java.util.Arrays;
import java.util.Scanner;

public class Main {
private static Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
String[] myStrings = getStrings(3);

}

public static String[] getStrings(int number){
System.out.println("Enter "+number+" strings\r");
String[] values = new String[number];
for (int i=0;i< values.length;i++){
values[i]=scanner.nextLine();
}
return values;
}
}

Mrexecexec
Автор

Great video, but can I have a question ? Why my scanner nextFloat read float from keyboard with comma instead of dot ?, can you help me . Thanks

ntphiep
Автор

I prefer a bang instead of "== false".

Pacvalham
Автор

What happened in while condition i didn't get

inoobbeyt