Home  • Programming • Java

Guess number game in java

import javax.swing.JOptionPane;

public class Problem3 {

	public static void main(String[] args) {
		int cont = 0;
		int won=0,loss=0;
		while (cont==0){


			//RANDOM NUMBER GENERATION
		    int random_number= (int)(Math.random()*6+1);

			System.out.println(random_number);   //<----------- JUST TO CHECK<br/>THENUMBER!!!!!

			//USER INPUT
			int user_number=Integer.parseInt(JOptionPane.showInputDialog("Guess<br/>a number between 1 and 6!"));

			if(random_number==user_number){
				JOptionPane.showMessageDialog(null,"YOU HAVE<br/>WON!:)","RESULT",0);
				won=won+1;
			}

			else {
				JOptionPane.showMessageDialog(null,"YOU HAVE<br/>LOST!:(","RESULT",0);
				loss=loss+1;
			}

			cont = JOptionPane.showConfirmDialog(null,"Wanna<br/>Playagain?","Continue?",0);

		}

		JOptionPane.showMessageDialog(null,"Won : "+won+"  Loss:<br/>"+loss,"Number of Wins and Lost!!",0);

	}

}

Comments 3


Try this
thank you sir!! :D it works fine now, though :P
Thank you sir.

Share

Copyright © 2024. Powered by Intellect Software Ltd