-1

Im running into a small error that im just a bit confused on. I have fixed many of the problems ive had but cannot figure out how to get this running. Any help with this error?small error

{
  int Y = 0;
  int N = 0;

  public static void main( String[] args ) throws java.lang.Exception
  {

    Scanner reader = new Scanner(System.in);
    System.out.println("Would you like to play a game? [Y] for yes, [N] for no");
    int playGame = reader.nextInt();
    if ( playGame == 'Y' )
    {
 System.out.println("Good then lets continue!");
    }
    else
    {
 System.out.println("Have a good day!");
    }
    System.out.println("Would you like to play Pick 3, Pick 4 or Pick 5? [3] for Pick 3, 

[4] for Pick 4, [5] for Pick 5");
    int pickGame = reader.nextInt();
    if ( pickGame == '3' )
    {
 System.out.println("You have chosen Pick 3 ");
    }
   }
}
Wacknjack
  • 3
  • 2
  • 5
    We'll need to see a bit more code than that. At the very least a complete class. – Andrew Regan Feb 06 '16 at 23:47
  • Ive put in one of the classes ive created. Im more looking on how to have the user input of y for yes or n for no do something when asked. – Wacknjack Feb 07 '16 at 00:09
  • Well ok.... But what is the actual question ? At the moment i can see nothing but some random code and general problem without pinpointing the exact location where you are having problems – Maciej Cygan Feb 07 '16 at 00:36
  • Hi and welcome to SO. You seems to have a rather broad question. Please have a look at the tour and how to ask a good question. Also please take your time to format and put relevant information to your question. In addition to that, please note, that this is not a "please code for me" page. We won't make your homework. Ask precise question to a given problem. – Marcinek Feb 07 '16 at 00:46
  • yes im sorry. The questions i want the computer to ask are... – Wacknjack Feb 07 '16 at 00:55
  • Would you like to play a game? What would you like to play Pick 3 Pick 4 or Pick5? How many times would you like to play? Im looking for how to find an if else statement to determine what the user put in order to move to the next question or terminate. – Wacknjack Feb 07 '16 at 00:56

1 Answers1

0

I would highly recommend reading up more on Java input and output methods as well as reading input from the user as you are inexperienced in this. However looking at your code it seems that you have a general idea of how it is done. You'd then use a conditional statement/loop to check the user input and make a decision based on that.

I'd suggest reading up on Java Decision Making and more directly the IF-ELSE statement.

Your goal is to learn how to use a conditional statement to evaluate the user's input and perform an action based on it.

A simple example would be

public class Something
{
    public static void main( String[] args )
    {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int i = scan.nextInt(); //To parse the text into an int
        ...
    }
}
Community
  • 1
  • 1
Keno
  • 2,018
  • 1
  • 16
  • 26