1

This is my code:

package santaclaus;
import java.util.*;

public class SantaClaus {


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Have you been good this year? (1 = Yes, 2 = No)");
        int good;
        good = scan.nextInt();
        System.out.println("Have you been naughty or nice?");
        String naughtynice;
        naughtynice = scan.nextLine();

        if(good == 1 && "nice".equals(naughtynice)){
            System.out.println("You will get presents from Santa Claus");
        }else if(good == 2 && "naughty".equals(naughtynice)){
            System.out.println("Your only getting coal this year");
        }else if(good == 1 && "naughty".equals(naughtynice) || good == 2 && "nice".equals(naughtynice)){
            System.out.println("You'll just have to wait to Christmas morning to see!");
        }
    }

}

When I run this I get this:

run:
Have you been good this year? (1 = Yes, 2 = No)
1
Have you been naughty or nice?
BUILD SUCCESSFUL (total time: 1 second)

How do I make it so I can input "naughty or "nice"? and then for it to proceed to the if statement thing? Sorry I am bad at this :/

Pshemo
  • 113,402
  • 22
  • 170
  • 242

0 Answers0