I have create a small program in java but when i try to run it the compiler give me the message : bad operand types for binary operator '>' .Also i cant understand the meaning of an other message: error: class Exercise1 is public, should be declared in a file named Exercise1.java the code is in the follow lines:
enter code here
import java.util.Random;
import java.util.Scanner;
public class Exercise1 {
public static void main(String[] args) {
Random random = new Random();
try (Scanner scan = new Scanner(System.in)) {
// υλοποίηση της άσκησης
int guess=0;
while (guess!=random){
System.out.println("Δώσε έναν αριθμό μεταξύ 1 και 100:");
guess=scan.nextInt();
if (guess<random){
System.out.println(guess+"είναι χαμηλό. Ξαναπροσπάθησε!");
System.out.println("Δώσε έναν αριθμό μεταξύ"+ guess + "και" + random);
}
else if(guess>random){
System.out.println(guess+"είναι υψηλό. Ξαναπροσπάθησε!");
System.out.println("Δώσε έναν αριθμό μεταξύ"+ guess + "και" + random);
}
else{
System.out.println("Συγχαρητήρια!");
}
playAgain=scan.next();
}while(playAgain.equalsIgnoreCase("y"));
scan.close();
}
}
}
Aucun commentaire:
Enregistrer un commentaire