I tried to make a program where the range of two numbers will be randomly generated. And you try to guess which number is it. Then it will show you score and ask you for play again
public class Main {
public static void main(String[] args) {
int min, max, random, choose, player = 0, pc = 0;
String helping;
char anwser='y';
Scanner key = new Scanner(System.in);
while (anwser=='y') {
System.out.print("First number: ");
min = key.nextInt();
System.out.print("Second number: ");
max = key.nextInt();
Random rand = new Random();
random = rand.nextInt(max - min) + min;
System.out.println("Try guess which number computer thoughts (in range from " + min + " to " + max + ")");
// i think that the problem is here
helping=key.nextLine();
choose=Integer.parseInt(helping);
//
if (choose == random) {
System.out.println("you win ");
System.out.println("computer thoughts number " + random);
player += 1;
System.out.println("Player has " + player + " points. computer has " + pc+ " points\n---------------------------------------------------------");
}
else {
System.out.println("you lose ");
System.out.println("computer thoughts number " + random);
computer += 1;
System.out.println("player has " + player + " points. computer has " + computer + " points\n--------------------------------------------");
}
System.out.println("Play again (y/n)?");
anwser = key.nextLine().charAt(0);
}
}
}
Aucun commentaire:
Enregistrer un commentaire