Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best way to get user input

 
Karl Collins
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have been learning java in school. Were only learning the extreme basics so please bear with me

Were using a file ( I think its called a library ) to grab user input an then display it on screen in our java programs.

I want to learn how to avoid using the program and have been looking up tutorials on YouTube.
I seen the scanner but its confusing as to how I would use it in a program such as this. Also is there a better option than scanner?

What I want to do is ask what age are you?

then age will equal the users input.

 
Karl Collins
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I have since figured all of this out!

It took a while but I'm beginning to grasp the use of the Scanner!
 
Satyen Singh
Greenhorn
Posts: 21
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Karl,

Don't think that Scanner is confusing or hard understand.
Remember Java's 1st Feature is that Java is "Simple" so, nothing is hard in java.
Scanner is very easy.
I will explain you how to use it and why .......

Now, If you want to read user input age from the console.
following is the code snippet in java using scanner.

 
Randall Twede
Ranch Hand
Posts: 4439
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you also might want to read about JOptionPane. it will display a separate dialog window to get user input.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49403
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satyen Singh wrote:. . . . Remember Java's 1st Feature is that Java is "Simple" so, nothing is hard in java. . . .
You have misunderstood the intention behind “simple”. It means that a programmer can remember all the rules, without having to look them up. I am not at all convinced they have achieved that intention, least of all since the introduction of generics in Java5.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic