Skip to content

Commit

Permalink
Added JavaDateAndTime.java ronijpandey#2
Browse files Browse the repository at this point in the history
  • Loading branch information
sho3hit authored Oct 29, 2017
1 parent 3c68670 commit e1e22fc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions JavaDateAndTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;

public class JavaDateAndTime {
static List<String> days = Arrays.asList("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY");

public static String getDay(String day, String month, String year) {

int y = Integer.parseInt(year);
int m = Integer.parseInt(month);
int d = Integer.parseInt(day);

Calendar c = Calendar.getInstance();
c.set(y, m-1, d);

int p = c.get(Calendar.DAY_OF_WEEK);
String s = days.get(p-1);
return s;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String month = in.next();
String day = in.next();
String year = in.next();

System.out.println(getDay(day, month, year));

}
}

0 comments on commit e1e22fc

Please sign in to comment.