| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- import java.util.Scanner;
-
- public class Main{
-
- public static void main(String[] args){
-
- Scanner stdin = new Scanner(System.in);
-
- int num = 21, usrNum, sum = 0;
- boolean isValid = false;
- boolean isTrue = false;
-
- while(!isValid){
- System.out.println("Enter a number (between 0 and 50) to guess the mystery number (-1 to exit): ");
- usrNum = stdin.nextInt();
- if(usrNum == -1){
- break;
- }
- while(!isTrue){
- if(usrNum>=0 && usrNum<=50){
- isTrue = true;
- } else if(usrNum == -1){
- break;
- } else{
- System.out.println("Number out of range\n");
- System.out.println("Enter a number (between 0 and 50) to guess the mystery number (-1 to exit): ");
- usrNum = stdin.nextInt();
- }
- }
-
- if(usrNum == -1){
- break;
- }
- if(usrNum<num){
- System.out.println("Incorrect... number is to small\n");
- } else if(usrNum>num){
- System.out.println("Incorrect... number is to large\n");
- } else if(usrNum == num){
- System.out.println("Correct! The number was " + num);
- isValid = true;
- }
- sum++;
- }
- System.out.println("Total number of tries is: " + sum);
- }
- }
|