Assignemnt #55 and NumberGuessing
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Forty-Fifth Program
/// file name: NumberGuessing.java
/// date finished: 11/18/15
import java.util.Random;
import java.util.Scanner;
public class NumberGuessing
{
public static void main ( String[] args )
{
Random r = new Random();
int response, x = 1 + r.nextInt(10);
Scanner keyboard = new Scanner(System.in);
System.out.print("I'm thinking of a number between 1 and 10. What is it?");
response = keyboard.nextInt();
if (response == x)
{
System.out.println("Congrats! You got the right number it was " + x);
}
else
{
System.out.println("Sorry my number was " + x);
}
}
}
Picture of the output