Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

program able to compile and execute but output was wrong.

 
Ayukawa Madoka
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm writing a program that accepts an integer value from a user and determine whether it's an even or odd number and then displays the integer taken from the user onto the screen. the program was able to compile and execute but the weird thing is the display result wasn't correct. is there anything wrong with my program? or the method that i used to differentiate between even and odd number is wrong? :roll:

 
Will Carpenter
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always have problems with System.in.read() when trying to accept mathematical input. I think it's because the Carriage Return and Next Line Characters that happen each time you hit "enter" get added onto the character that was entered. Try using a BufferedReader.
 
Will Carpenter
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See for example the answers to my earlier posts entitled "Input from keyboard" in which I encountered a similiar problem....
 
Ayukawa Madoka
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see. ok thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic