Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Variable error help

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Variable error help

    Hello,
    My assignment is to write code simulating dice, generating 10000random numbers between 1-6. Then I have to display the number of 1's that appeared, the number of 2's that appeared, etc in a joptionpane like this:

    The number of 1s appeared is
    The number of 2s appeared is
    The number of 3s appeared is
    The number of 4s appeared is
    The number of 5s appeared is
    The number of 6s appeared is

    This is my code so far:
    public class ARG
    {
    		public static void main(String[] args)
    		{
     
     
    			  int[] A = new int[10000];
     
    			for(int i=0; i<A.length; i++)
    				A[i] = 1 + (int) (6*Math.random());
             }
             {
             for(int i=0; i<A.length; i++)
    			System.out.println(A[i]);
     
     
    		for(int i = 0; i < 6; i++)
       		System.out.println("Total number of " + (i+1) + " = " + A[i]);
     
    		}
     
    }

    The variable errors I keep getting are:
    F:\ARG.java:13: error: cannot find symbol
    for(int i=0; i<A.length; i++)
    ^
    symbol: variable A
    location: class ARG
    F:\ARG.java:14: error: cannot find symbol
    System.out.println(A[i]);
    ^
    symbol: variable A
    location: class ARG
    F:\ARG.java:18: error: cannot find symbol
    System.out.println("Total number of " + (i+1) + " = " + A[i]);
    ^
    symbol: variable A
    location: class ARG
    3 errors

    Tool completed with exit code 1

    I'm a beginner so please if you can help me in any way, it would be appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Variable error help

    Check that the {}s are properly paired.
    I can't tell in the code that you posted because the vertical alignment of statements doesn't follow standards.
    The statement with the beginning { should start directly above the ending }
    Your {}s waver left and right and make it hard to see what code belongs where.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Variable error help

    Comment {} on line 11, then it would be like this

    public class ARG
    {
    public static void main(String[] args)
    {


    int[] A = new int[10000];

    for(int i=0; i<A.length; i++)
    A[i] = 1 + (int) (6*Math.random());
    //}
    //{
    for(int i=0; i<A.length; i++)
    System.out.println(A[i]);


    for(int i = 0; i < 6; i++)
    System.out.println("Total number of " + (i+1) + " = " + A[i]);

    }

    }

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Variable error help

    You actually closed your main method and class bracket before your for loop, so the computer never understands what is your for loop for, change your bracket and it should take out those errors it's showing to you now

    Hope this helps

Similar Threads

  1. Replies: 5
    Last Post: November 16th, 2011, 11:22 AM
  2. Replies: 10
    Last Post: October 26th, 2011, 02:22 PM
  3. Replies: 4
    Last Post: October 20th, 2011, 11:26 AM
  4. Variable Error
    By SipOfJava in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 14th, 2011, 11:48 AM
  5. Semantic error: Variable assignment: please help!!
    By humdinger in forum Java Theory & Questions
    Replies: 1
    Last Post: November 17th, 2009, 02:28 PM