Guess the number
unknown
java
2 years ago
848 B
12
Indexable
package myfirstjava;
import java.util.Scanner;
import java.util.Random;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int randomNumber = random.nextInt(100) + 1;
int attempts = 0;
System.out.println("Welcome to guess the number");
while(true) {
System.out.println("Coloque um numero: ");
int input1 = Integer.valueOf(scanner.nextLine());
attempts++;
if(input1 < randomNumber) {
System.out.println("its below try again");
}
else if(input1 > randomNumber) {
System.out.println("its above try again");
}
else if(input1 == randomNumber) {
System.out.println("you passed");
break;
}
}
}
}Editor is loading...