Question
My java program won't run, the only thing that comes up is in the console. Could you please tell me what I'm doing wrong and
My java program won't run, the only thing that comes up is
import javax.swing.JOptionPane; import java.util.Random;
public class RandomNumberGuessingGame{
public static void main( String [ ] args ) { Random randomObjectNumber = new Random(); int RandomNumber = randomObjectNumber.nextInt( 101 ); boolean NumberEnteredCorrect = false; String userInput; int NumberUserGuessed; int NumberOfTimeUserGuessed = 0; while( NumberEnteredCorrect ) { NumberOfTimeUserGuessed = NumberOfTimeUserGuessed + 1; userInput = JOptionPane.showInputDialog( " Guess the number: " ); NumberUserGuessed = Integer.parseInt ( userInput ); if( NumberUserGuessed > RandomNumber ) { JOptionPane.showMessageDialog( null, " To high, try again" ); }//End of If statement else if(NumberUserGuessed < RandomNumber ) { JOptionPane.showMessageDialog( null, " To low, try again" ); }//End of else if statement else { JOptionPane.showMessageDialog( null, " Good job you guessed the number right."+ NumberOfTimeUserGuessed + " Tries"); NumberEnteredCorrect = true; }//End else statement }//End of while loop System.exit( 0 );
}//End class
}//End main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started