Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement help

 
Paul Phoenix
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I have two quesions actually.

PART 1

What I am trying to get this program do is ask math three math quesions. If the answer is right it will print out it is right and you will get one point or it will be wrong and get zero points. I have done that. However, when i try to declare a variable that is the total of the scores it says that the java program can't find the variables.




Part 2


my second question is just what to set the if statement equal to so that it reads that the user has inputted nothing and just hit enter.

Say for example

if (stringOne= no input they just hit enter here)
{System.out.println("you typed nothing");

 
fred rosenberger
lowercase baba
Bartender
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should research what 'variable scope' is.

On line 12, you first declare the variable score1. However, the next line you leave the block, the variable falls out of scope, and thus effectively doesn't exist any more. You should define your variable outside the if-else blocks, if you want to see them outside the if-else blocks.

I believe for question 2, you will get an empty string..."". You could check the length of the string (although you may also get the carriage return) to see if it is zero.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic