• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

if statement help

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic