samedi 30 décembre 2017

using int instead of boolean in if statements

I'm working on a small program which uses switch statements to identify the day of the week using a scanner input.

package Dummies;
import java.util.Scanner;
public class DaysOfTheWeek {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner keyboard = new Scanner(System.in);
        int day = keyboard.nextInt();
        switch(day) {
        case 1:
            if(day = 1) {
                System.out.println("Sunday");
            }
        }
    }

}

I wanted the programme to tell me what the day of the week it is depending on what number the user inputs, for example in the United States the first day of the week is Sunday so if the user inputs "1" Sunday would be printed. I wanted the switch statement with each case containing an if statement for a detailed response. The issue I'm having here is that i can't convert an int to a boolean in an if statement and I wanted to ask if anyone knows how I can solve it. I know that my code isn't complete.

Thanks for help.

Aucun commentaire:

Enregistrer un commentaire