• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Best way to get user input

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 21
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you also might want to read about JOptionPane. it will display a separate dialog window to get user input.
 
Marshal
Posts: 80639
472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic