Adding early CS challenge solutions
This commit is contained in:
28
CS6 - Challenge Solution/Main.java
Normal file
28
CS6 - Challenge Solution/Main.java
Normal file
@@ -0,0 +1,28 @@
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Random random = new Random();
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
int randomValue = random.nextInt(101);
|
||||
|
||||
int guess = -1;
|
||||
|
||||
while(randomValue != guess) {
|
||||
System.out.print("Guess the number: ");
|
||||
guess = scan.nextInt();
|
||||
|
||||
if(guess < randomValue) {
|
||||
System.out.println("You're too low");
|
||||
} else if(guess > randomValue) {
|
||||
System.out.println("You're too high");
|
||||
} else {
|
||||
System.out.println("You guessed the right number");
|
||||
}
|
||||
}
|
||||
|
||||
scan.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user