Skip to main content

Can't compile my code, need help!

2 replies [Last post]
happygirl1184
Offline
Joined: 2011-11-28
Points: 0

Hello! I am a beginner and not very good at java. I am having trouble compiling my code. Does anyone have some time to look over it to see what I've done wrong?? The compiling error that I keep receving is saying it cannot find the symbol for the "if ( counter..." part of the program. symbol: variable counter. Location: class RandomIntegers2. Any help is greatly appreciated!!! thanks!!

Here is the question: Write a program that rolls a four sided die 4 times and stores results in int a [4].
Here is my code:
import java.util.Random;
public class RandomIntegers2
{
public static void main( String[] args )
{
Random randomNumbers = new Random();
int face;
face = 1 + randomNumbers.nextInt( 4 );
System.out.printf( "%d ", face );
if ( counter % 5 == 0 )
System.out.println();
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
OneJumpedUp
Offline
Joined: 2012-04-05
Points: 0

Hi I have made mode to your code, it was NEVER going to work
have a look aat this see if you can see how it works, and then play ....

public static void main(String[] args) 
{
    Random randomNumbers = new Random();
    int face;
    for( int nLoop = 0; nLoop < 100; nLoop++ ) /// loop added to generate more ouput
    {
        face = 1 + randomNumbers.nextInt( 5 ); // with this at 4, it will never be true
        if(( face % 5 ) == 0 )
        {
            System.out.printf( "woo hoo, face is %d !\n", face ); // what are you outputting ???
        }
        else
        {
            System.out.printf( "nope, not yet, face is %d, boo hoo !\n", face );
               
        }
    }
}   

P.S. try and format your code, makes it easier to read, and more people will reply

vlsn.kakitha
Offline
Joined: 2011-12-09
Points: 0

How you can use the variable count with out declaring .check once its declaration.