From edf1a591855d890115d21163458ab7ef685be28a Mon Sep 17 00:00:00 2001 From: Bo Lee Date: Wed, 7 Feb 2018 00:38:43 -0500 Subject: [PATCH 1/2] Guess the number --- src/main/java/Main.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..ccc4ed3 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,29 @@ +import java.util.Random; +import java.util.Scanner; + /** * Created by iyasuwatts on 10/17/17. */ public class Main { - public static void main(String[] args){ - + public static void main(String[] args) { + Scanner userInput = new Scanner(System.in); + Random rand = new Random(); + int count = 0; + int mysteryNum = rand.nextInt(1000); + System.out.println("Please guess to find the mystery number. The mystery number is between 0 and 1000."); + while (true) { + int userNum = userInput.nextInt(); + count++; + if (userNum > mysteryNum) { + System.out.println("Too large. Please guess again."); + } else if (userNum < mysteryNum) { + System.out.println("Too small. Please guess again."); + } else if (userNum == mysteryNum) { + System.out.println("Correct guess!"); + System.out.println("It took you " + count +" guesses."); + break; + } + } } } From 4714940a39efd2f4a34f1a5b571a56f71d1b20a4 Mon Sep 17 00:00:00 2001 From: Bo Lee Date: Sun, 1 Apr 2018 21:54:38 -0400 Subject: [PATCH 2/2] Refactored code --- java/lang/annotations.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 java/lang/annotations.xml diff --git a/java/lang/annotations.xml b/java/lang/annotations.xml new file mode 100644 index 0000000..09ef3eb --- /dev/null +++ b/java/lang/annotations.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file