import java.util.Random;
import java.util.*;
public class PartThree
{
public static void main(String args[]){
int wrong = 0; //number of times guessed wrong
int attempts = 0; //total attempts
int keepGoing = 1;
System.out.println("Guess a number between 1 to 50!");
wrong++;
while (keepGoing == 1){
int x = 1;
Random rand = new Random();
int rnd = rand.nextInt(50); //computer's random number
do{
try{
Scanner scan = new Scanner(System.in);
int guessInt = scan.nextInt();
if (guessInt == rnd){
System.out.println("You got in " + wrong + " attempts");
wrong = 0;
}
else if (guessInt < rnd){
System.out.println("Too low. Try again " );
} else if (guessInt > rnd) {
System.out.println("Too high. Try again ");
}
}//try
catch(Exception e){//error handling
System.out.println("Follow the directions!");
}
}while(x == 1);//do (keep looping until directions are followed and x = 2)
} //while
} //method
} //class
bat ganyan lods hindi mabasa ang attempts kung mabasa man 1 nakalagay
import java.util.*;
public class PartThree
{
public static void main(String args[]){
int wrong = 0; //number of times guessed wrong
int attempts = 0; //total attempts
int keepGoing = 1;
System.out.println("Guess a number between 1 to 50!");
wrong++;
while (keepGoing == 1){
int x = 1;
Random rand = new Random();
int rnd = rand.nextInt(50); //computer's random number
do{
try{
Scanner scan = new Scanner(System.in);
int guessInt = scan.nextInt();
if (guessInt == rnd){
System.out.println("You got in " + wrong + " attempts");
wrong = 0;
}
else if (guessInt < rnd){
System.out.println("Too low. Try again " );
} else if (guessInt > rnd) {
System.out.println("Too high. Try again ");
}
}//try
catch(Exception e){//error handling
System.out.println("Follow the directions!");
}
}while(x == 1);//do (keep looping until directions are followed and x = 2)
} //while
} //method
} //class
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.