Assignment 65; GuessForever
Code
// Donovan Rich
// Period 6
// Number-guessing with a Counter
// GuessForever.java
// 12/9/2015
import java.util.Random;
import java.util.Scanner;
// I know this is not technically the right program, but
// I didn't really realize that until after I had finished it.
// I believe it demonstrates the same concepts, though.
public class GuessForever
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int guess, guesses=0, ans = 1 + r.nextInt(100);
System.out.print( "plz guess num 1-100 or i report u " );
guess = keyboard.nextInt();
while (guess != ans )
{
if ( guess < ans )
System.out.println( "sry ur too low! try agen " );
else if ( guess > ans )
System.out.println( "sry n00b ur too high kek try agen " );
guesses++;
guess = keyboard.nextInt();
}
if ( guesses > 0)
{
guesses++;
System.out.println( "hahaahaaa u got it right kid B^) only took " + guesses + " tries scrub " );
}
else
{
guesses++;
System.out.println( "wow 1 shot 1 correct guess nice job you cheeky scrublarodafr" );
}
}
}
Picture of the output