Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  WeekdayName.java
Language: JAVA
Code:
import java.util.GregorianCalendar;
 
public class WeekdayName {
     public static String weekdayName( int weekday ) {
          String result = "";
 
          if ( weekday == 1 ) {
               result = "Sunday";
          }
          else if ( weekday == 2 ) {
               result = "Monday";
          }
          // * add more if statements here to complete the table
 
          return result;
     }
 
 
     public static void main( String[] args ) {
          // All the code below is perfect. Don't change it!
          System.out.println( "Weekday 1: " + weekdayName(1) );
          System.out.println( "Weekday 2: " + weekdayName(2) );
          System.out.println( "Weekday 3: " + weekdayName(3) );
          System.out.println( "Weekday 4: " + weekdayName(4) );
          System.out.println( "Weekday 5: " + weekdayName(5) );
          System.out.println( "Weekday 6: " + weekdayName(6) );
          System.out.println( "Weekday 7: " + weekdayName(7) );
          System.out.println( "Weekday 0: " + weekdayName(0) );
          System.out.println();
          System.out.println( "Weekday 43: " + weekdayName(43) );
          System.out.println( "Weekday 17: " + weekdayName(17) );
          System.out.println( "Weekday -1: " + weekdayName(-1) );
          int who_knows = -50 + (int)(Math.random()*100);
          System.out.println( "Weekday " + who_knows + ": " + weekdayName(who_knows) );
 
          GregorianCalendar cal = new GregorianCalendar();
          int dow = cal.get(GregorianCalendar.DAY_OF_WEEK);
 
          System.out.println( "\nToday is a " + weekdayName(dow) + "!" );
     }
}
          
Comments: