Java - Use if else statement to output day of week

Description

Use if else statement to output day of week

Demo

public class DayOfWeek {

  public static void main(String args[]) {
    int year = 13;
    int month = 0;
    int day = 8;//from w  w  w.  ja  va2 s .  co  m

    int dayOfWeek = (day + month + year + (year / 4) + 6) % 7;

    if (dayOfWeek == 0) {
      System.out.println("Sunday");
    }
    else if (dayOfWeek == 1) {
      System.out.println("Monday");
    }
    else if (dayOfWeek == 2) {
      System.out.println("Tuesday");
    }
    else if (dayOfWeek == 3) {
      System.out.println("Wedneday");
    }
    else if (dayOfWeek == 4) {
      System.out.println("Thurday");
    }
    else if (dayOfWeek == 5) {
      System.out.println("Friday");
    }
    else
      System.out.println("Sarurday");
  }
}

Related Topic