• Post Reply Bookmark Topic Watch Topic
  • New Topic

Functions  RSS feed

 
Akshith Reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii sir, today i wrote an exam in which i got a program which I was unable to solve so please help me out of this and the program was:



So here my doubt is how to take input and print output using scanner???
Thank you..
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us how you approached this problem and what issues you were facing.

For a start, what do you know about STDIN and STDOUT?
 
Akshith Reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, STDIN means to read the input from keyboard and STDOUT means to print output.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should approach this one small step at a time.  For example, you could decide to work on the method calculation first. That method does't care WHERE you get your data from, just that it gets passed in. Since it takes an int, you can work on it by calling it with a hard-coded value:

int result=calculation(7);

then write, test, fix, re-test...etc...over and over until you are SURE it is rock-solid.  Then once it works, you can work on getting data from STDIN.  Once you can do that, you can feed the data you get from STDIN into your calculation method.

Don't try and do it all at once.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!