• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Help in do while loop

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello i need help in program below , it asking me to input your name after inputing name it shows me that name, then it is asking me Do you want to continue (Y/N) at this stage it is working well but after pressing y it gives me first two statements at once what should i do?




Here is the output of this program.


Enter name: Muzafar
Name is: Muzafar
Do You Want To Continue (Y/N)?: y

Enter name: Name is:
Do You Want To Continue (Y/N)?:

thanks.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use name=input.next();

It will not work in case name contains more than one word....

One question why you extends Object class ? There is particulary no need of it. Object class is a super class of every class so each class will inherit all its property. Extends should be used carefully as we can use for extending only one class
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Varun K. Gupta wrote:use name=input.next();

It will not work in case name contains more than one word....

One question why you extends Object class ? There is particulary no need of it. Object class is a super class of every class so each class will inherit all its property. Extends should be used carefully as we can use for extending only one class





Thanks for answering Varun,
i Extended Object class because of knowing simple you have knowledge about that i know you have defined that class in your feedback , it was a simple example for let me remmember that Object class is super class for all classes all classes are extending Object class properties.

Your answer was well but not complete i know that it will work but not as i want it to work,
it should accept spaces between name you know.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Scanner object must swallow the end of line symbols:
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using Java 1.6, you should use the java.io.Console class. It's a little easier to use than Scanner when reading input from the command-line.

 
Marshal
Posts: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I disagree about Console. Scanner is more versatile; it will do all the parsing for you, so nextInt() actually returns an int. Also you only get a console when you open a Java program from the command line with the "java" tool. If you use javaw (as IDEs do), and probably even if you double-click an executable .jar, you get no console object, so trying to read from it will cause NullPointerExceptions.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pete stein wrote:Your Scanner object must swallow the end of line symbols:




Thank you very much
this is working for me, if i am using

instead of this
.
thanks you and all other friends who answered me.
 
Campbell Ritchie
Marshal
Posts: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muzafar Ali wrote:thanks you and all other friends who answered me.

You're welcome
 
I think I'll just lie down here for a second. And ponder this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic