Assignment #65 Number-Guessing with a Counter
Code
///Name: Ian Grant
///Period:5
///Project Name: Number-Guessing with a Counter
///File Name:NumGuessV4.java
///11/12/15
import java.util.Scanner;
import java.util.Random;
public class NumGuessV4
{
public static void main(String[] args)
{
Scanner stuff=new Scanner(System.in);
Random Rstuff=new Random();
int gus,ans;
int tries=0;
ans= 1+Rstuff.nextInt(10);
System.out.println("teh worst number gessing gaaame evar!!");
System.out.print("I'm thinking of a number between 1 and 10. Try to guess it! ");
gus=stuff.nextInt();
tries++;
while (gus != ans)
{
System.out.println("That is incorrect. Guess again.");
gus=stuff.nextInt();
tries++;
}
System.out.println("That's correct! You're a good guesser");
System.out.println("It only took you "+tries+" tries.");
}
}
Output