Results 1 to 2 of 2
  1. #1
    Mrlowrider is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default if statement help

    Well I have two quesions actually.

    PART 1

    What I am trying to get this program do is ask math three math questions. 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.
    Java Code:
    System.out.println("Enter an Integer:");
                 	int int1=keyboard.nextInt();
    	         System.out.println("Enter another Integer:");
    	         	int int2=keyboard.nextInt();
    	          System.out.println("Answer the following questions please.");
    	          	int guess1=keyboard.nextInt();
    	          			if (guess1==(int1*int2))
    	          				int score1= 1;
    	          				int score1= 0;
    	    	          	int guess2=keyboard.nextInt();
    	    	          			if (guess2==(int1/int2))
    	    	          				int score2= 1;
    	    	          				int score2= 0;
    	    	    	          	int guess3=keyboard.nextInt();
    	    	    	          			if (guess3==(int1%int2))
    	    	    	          				int score3= 1;
    	    	    	          				int score3= 0;
    	                  int total= score1+score2+score3;

    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");

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power


    Question 1- You're declaring the variables for each score inside each if statement, so they're only available inside their respective if blocks. Declare them (or just one score variable that you increment) outside of the if block.

    Question 2- What have you tried? What is keyboard? Is it a Scanner? Check out the API and experiment.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Replies: 2
    Last Post: 02-15-2011, 05:51 AM
  2. If Statement in SQL
    By Steffi1013 in forum JDBC
    Replies: 6
    Last Post: 04-10-2010, 03:19 PM
  3. need help in sql statement
    By chyeeqi in forum JDBC
    Replies: 6
    Last Post: 03-28-2010, 07:49 PM
  4. add an If Else statement and......uh????
    By sonny in forum New To Java
    Replies: 6
    Last Post: 03-04-2010, 06:57 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts