Community discussion forum

Error message

  • 2 years ago

    Hi I am having problems with my code.
    It is given me an error message stating "cannot find symbol variable
    NotCont"where the arrow is.
    Can some one help me with this please.
    Thanks ^_^ 
     

    import java.util.Scanner;
    public class IntegerSetTest
    {
            public static void main(String[] args)
            {
                    Scanner input = new Scanner (System.in);

                    System.out.println("Welcome to the Integer Set\n");

            System.out.println("This program is going to find the union " +
                    " or intersection of any two sets you enter" +
                    "\nPlease enter the number of sets: ");
            int  intArray[] = new int[100];
                    int value;
            try
            {
                    do
                    {
                            int i;

                            value = input.nextInt();
                            intArray[i]=value;
                            System.out.println("Enter -1 to end: ");
                            int NotCont = input.nextInt();
                            i++;
    --->                 }while(NotCont != -1);

                    for(int i=0; i<intArray.length;i++)
                    {
                            System.out.println(intArray[i]);
                    }
            }
            catch(NumberFormatException ex)
            {
            }
        }
    }

    </code>

  • 2 years ago

    you have

    do

    {

    int i;

    value = input.nextInt();

    intArray[i]=value;

    System.out.println("Enter -1 to end: ");

    int NotCont = input.nextInt();

    i++;

    } while(NotCont != -1);

    you need

    int NotCont = 0;

    do

    {

    int i;

    value = input.nextInt();

    intArray[i]=value;

    System.out.println("Enter -1 to end: ");

    NotCont = input.nextInt(); i++;

    } while(NotCont != -1);

    you cannot initialise a variable within a loop as there is a chance (usually slim but none the less) tjhat the program wont go into that loop and therefore wont be created. also you might have the same problem with your try catch so my want to put it out of there too
  • 2 years ago

    Ok, thanks

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!