5-2 WeekDays

posted Apr 2, 2014, 12:35 PM by Dlovan ismail   [ updated Apr 3, 2014, 8:32 AM ]

package weekdayes;
import java.util.Scanner;

public class WeekDayes 
{
        public static void main(String[] args) 
        {
            Scanner scan=new Scanner(System.in);

            System.out.println("Enter the weekday : ");
            System.out.println(weekdayName(scan.nextInt()));
        }
        
       /* The following method, for example, 
        returns the English name of the day of the week, given a number between 1 (Sunday) and 7 (Saturday):*/
        
        public static String weekdayName(int day)
        { 
            switch (day) 
            { 
             case 1: return "Sunday"; 
             case 2: return "Monday"; 
             case 3: return "Tuesday"; 
             case 4: return "Wednesday"; 
             case 5: return "Thursday"; 
             case 6: return "Friday"; 
             case 7: return "Saturday"; 
             default: return "Illegal value"; 
            }
       }
}

ċ
WeekDayes.java
(1k)
Dlovan ismail,
Apr 2, 2014, 12:35 PM
Comments