Error message

  • 13 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>

  • 13 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
  • 13 years ago

    Ok, thanks

Post a reply

Enter your message below

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

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson