Java Problem

Discussion in 'Mac Programming' started by CayceH, Feb 25, 2012.

  1. macrumors newbie

    Joined:
    Dec 23, 2011
    Location:
    United States
    #1
    import java.util.Scanner;

    public class HelloWorld {
    public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Choose a number between 1 and 10");
    if (keyboard == 1) { System.out.println("You are correct");
    } else System.out.println("Sorry try again");
    }
    }


    it says i can not have (keyboard == 1) so i tried to declare keyboard as an int but received another error how do i make it to where if someone types 1 on the keyboard that it will run the command?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2

Share This Page