• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Input Using Scanner Class

 
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any way to make take run time input using Scanner Class ?




Any Help on this would be appreciated !!!

 
Marshal
Posts: 80945
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That technique wll take input at runtime all right. Please count how often the if statement will run. Please also count how many inputs you need before the end of the if, which you do by counting the next() calls.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Tried the above Code but does not work. It keeps taking Input from user

 
Campbell Ritchie
Marshal
Posts: 80945
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is completely different code from what you had earlier, with different semantics. It looks as if you were guessing about different kinds of code, and guessing is always a bad idea. Don't create multiple Scanners reading System.in. Use one Scanner for System.in for the whole application and never close it.
Also, go through your loop and work out what happens to the loop variable (noOfElements) during the loop.

If you are trying to create an expression, why are you concatenating the whole thing into one String? Why don't you have classes for operators and operands and expressions? If you put the whole thing together into a String, you will have the same problem about breaking the String up later.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


THANKS This is what I was looking for ....
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic