aspose file tools*
The moose likes Beginning Java and the fly likes if statement help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if statement help" Watch "if statement help" New topic
Author

if statement help

Paul Phoenix
Greenhorn

Joined: Apr 10, 2011
Posts: 5
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

Joined: Oct 02, 2003
Posts: 11498
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if statement help