guess the number java
import java.util.Scanner;
import java.util.Random;
public class GuessingGame{
public static void main(String[] args) {
int random, guess, attempts;
Scanner keyboard = new Scanner(System.in);
Random generator = new Random();
random = generator.nextInt(100) + 1;
attempts = 1;
System.out.print("I am thinking of a number between 0 and 100, what do you think it is?");
guess = keyboard.nextInt();
while (guess != random) {
if (guess > random) {
System.out.print("Lower!");
attempts += 1;
}
else {
System.out.print("Higher!");
attempts +=1;
}
}
System.out.print(random + "is the correct answer and it took you" + attempts + "attempts to guess it!");
}
}
Also in Java:
- how to create a thread local variable in java
- square root java
- print arraylist java
- crit chance in java
- recursive function for fibonacci series in java javascript
- java swing button on click
- bukkit java set leather armor color from hex
- gson parse json
- adding an element to the end of a linked list java
- how to minimize jframe in java
- Java.awt graphics tutorial
- java replace element in list
- gat environment variables java
- java sum of two numbers program intellij
- system.arraycopy java
- what is a float java
- how to create a draw Rectangle in java
- java how to serialize a file into a local server
- bukkit java get max players
- how to get individual words from a string in java
- org.mapstruct maven dependency
- java initialize int array
- bracket balancing program in java
- java syntax