Guess a number program with Java

前端 未结 6 1732
情话喂你
情话喂你 2021-01-28 12:06

I am trying to create a program in Java in which the computer randomly guesses a number between 1-100 and allows the user to guess to the number.

If the number is lower

6条回答
  •  没有蜡笔的小新
    2021-01-28 12:50

    Well I crossed across this topic and would like to share the code I figured out too since it was a fun question.This can even be used as a simple game.below is the psuedocode for it :D

    do{
            number=(int)(Math.random()*100);
    
       }while(number<10);
    do
        {
      lottery=Integer.parseInt(JOptionPane.showInputDialog(null,"guess the two digit number which is in my mind!!!! \nenter the number"));
      if(numberlottery)
      {
          JOptionPane.showMessageDialog(null,"guess a more higher number");
          count ++;
         }
      else
          JOptionPane.showMessageDialog(null,"you have guessed the correct number "+number+" in"+count+" tries");
        }while(lottery!=number);
    

提交回复
热议问题