Skip to content

Finished project #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,81 @@
/**
* Created by iyasuwatts on 10/17/17.
*/

import java.util.Random;
import java.util.Scanner;

public class Main {

public static void main(String[] args){

public static void main(String[] args) {

/*
- Write a guessing game which prompts a user to guess a mystery number within some range
- After every guess the program should display some variation of "too large", "too small", "correct"
- Display the number of guesses before successfully guessing correctly
- A number that is input consecutively should register as a single guess.
*/

//Variables
int counter = 0;
Random randomInt = new Random();
int number;
int currentGuess;
int previousGuess = 0;

//How to get a random number
number = randomInt.nextInt(10);
//System.out.println(number);

//Scanner
Scanner scanner = new Scanner(System.in);

do {


System.out.println("Guess a number: ");
currentGuess = scanner.nextInt();


if(previousGuess != currentGuess){

counter++;
}



if (currentGuess == number) {

System.out.println("You guessed correct");


} else if (currentGuess > number) {

System.out.println("Too Large");

} else if (currentGuess < number) {

System.out.println("Too Small");

}


previousGuess = currentGuess;


} while (currentGuess != number);







System.out.println("You guessed " + counter + " of time(s).");


}


}