HOME

HOME

Number guessing game in java




package com.company;
import java.util.Scanner;
import java.util.Random;
class game {
int chose;
int guess;
game() {
Random r = new Random();
guess = r.nextInt(100);
System.out.println("enter your guess number");
}
boolean guess() {

if (chose < guess) {
System.out.println("your guess is low \n wrong");
return false;
} else if (chose > guess) {
System.out.println("your guess is high\n wrong");
return false;
}
else{
System.out.println("congratulation your guess is right");
}
return true;
}
public void input() {
Scanner s = new Scanner(System.in);
chose = s.nextInt();
}
}
public class guessingGAME {
public static void main(String[] args) {
game game = new game();
boolean b= false;
int d;
d=0;
while(!b) {
game.input();
b = game.guess();
d=d+1;
}
System.out.printf("you take %d attempts of win",d);

}
}



No comments:

Post a Comment