Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package randomno;
- import java.util.Scanner;
- /**
- *
- * @author David
- */
- public class Randomno {
- /**
- * @param args the command line arguments
- */
- static boolean isRunning = true;
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner s = new Scanner (System.in);
- String input;
- int guess;
- while (isRunning)
- {
- int answer = (int)(100 * Math.random());
- System.out.println("Guess any between 1 and 100 or type \"Quit\" to exit:");
- while (true)
- {
- input = s.nextLine();
- if (input.toLowerCase().equals("quit") || input.toLowerCase().equals("exit"))
- {
- isRunning = false;
- break;
- }
- try
- {
- guess = Integer.decode(input);
- if (guess == answer)
- {
- System.out.println("You Win");
- System.out.println("Play again?");
- input = s.nextLine();
- if (input.toLowerCase().equals("quit") || input.toLowerCase().equals("exit") || input.toLowerCase().equals("no") || input.toLowerCase().equals("n"))
- {
- isRunning = false;
- break;
- }
- else if (input.toLowerCase().equals("yes") || input.toLowerCase().equals("y"))
- {
- break;
- }
- else
- {
- System.out.println("Invalid response, so then yes.");
- break;
- }
- }
- else if (guess < answer)
- {
- System.out.println("Higher Than That...");
- }
- else
- {
- System.out.println("Lower Than That...");
- }
- }
- catch (NumberFormatException e)
- {
- System.out.println("Not a number! Try again!");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment