Results 1 to 3 of 3
  1. #1
    imran1991 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Unresolved compilation problems:

    import java.util.Random;
    import java.util.*;

    public class rendom_number {

    /**
    Suppose you want to develop a program to let a first-grader practice addition. The program
    randomly generates two single-digit integers, number1 and number2, and displays to the student
    a question such as “What is 7+9 ”, as shown in the sample run. After the student types
    the answer, the program displays a message to indicate whether it is true or false.
    */
    public static void main(String[] args) {


    do{
    Random rand = new Random();

    int num1=rand.nextInt(10);
    int num2=rand.nextInt(10);


    int input,sum;

    Scanner in=new Scanner(System.in);

    System.out.print("What is "+num1 +"+"+num2 +"=");
    input=in.nextInt();

    sum=num1+num2;

    if(sum==input)
    {
    System.out.print("True");
    }
    else
    {

    System.out.print("False");
    }

    }while(sum != input);


    }

    }


    What is that error plz someone explane

    ....in last line while loop "sum" and "input" not excess ...error is "sum cannot be resolved to a variable
    input cannot be resolved to a variable"...

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default Re: Unresolved compilation problems:

    Don't declare the variables sum and input in the body of your do ... while loop, but declare them above the 'do' part of your loop.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    imran1991 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Unresolved Compilation Problems
    By eck0 in forum New To Java
    Replies: 1
    Last Post: 05-19-2011, 12:17 PM
  2. Replies: 0
    Last Post: 06-20-2010, 05:23 PM
  3. java.lang.Error: Unresolved compilation problems
    By jon80 in forum New To Java
    Replies: 0
    Last Post: 06-07-2009, 10:04 PM
  4. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 08:17 PM
  5. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:49 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
  •