Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package harpic;
- import java.util.Scanner;
- public class Harpic {
- public static void main(String[] args) {
- Scanner input=new Scanner(System.in);
- int A=0,B,C,D;
- String month,again;
- for(int j=0;;j++){
- for (int i = 0;; i++) {
- System.out.print("Please enter the month: ");
- month= input.nextLine();
- System.out.print("Please enter the day of the month: ");
- B=input.nextInt();
- System.out.print("Please enter the year: ");
- C=input.nextInt();
- if("March".equals(month) && B<=31){
- A=3;
- break;
- }
- else if("April".equals(month) && B<=30){
- A=4;
- break;
- }
- else if("May".equals(month) && B<=31){
- A=5;
- break;
- }
- else if("June".equals(month) && B<=30){
- A=6;
- break;
- }
- else if("July".equals(month) && B<=31){
- A=7;
- break;
- }
- else if("August".equals(month) && B<=31){
- A=8;
- break;
- }
- else if("September".equals(month) && B<=30){
- A=9;
- break;
- }
- else if("October".equals(month) && B<=31){
- A=10;
- System.out.println("A = "+A);
- break;
- }
- else if("November".equals(month) && B<=30){
- A=11;
- break;
- }
- else if("December".equals(month) && B<=31){
- A=12;
- break;
- }
- else if("January".equals(month) && B<=31){
- A=13;
- C=C-1;
- break;
- }
- else if("February".equals(month) && B<=29){
- A=14;
- C=C-1;
- break;
- }
- else {
- System.out.println("try again!");
- continue;
- }
- }
- int temp,year1,year2;
- temp=C;
- year1=temp%100;
- year2=temp/100;
- C=year1;
- D=year2;
- int ans;
- ans=(((13*(A+1)/5))+(C/4)+(D/4)+B+C+(5*D))%7;
- if(ans==0){
- System.out.println(month+" "+B+", "+temp+" is a Saturday");
- }
- if(ans==1){
- System.out.println(month+" "+B+", "+temp+" is a Sunday");
- }
- if(ans==2){
- System.out.println(month+" "+B+", "+temp+" is a Monday");
- }
- if(ans==3){
- System.out.println(month+" "+B+", "+temp+" is a Tuesday");
- }
- if(ans==4){
- System.out.println(month+" "+B+", "+temp+" is a Wednesday");
- }
- if(ans==5){
- System.out.println(month+" "+B+", "+temp+" is a Thursday");
- }
- if(ans==6){
- System.out.println(month+" "+B+", "+temp+" is a Friday");
- }
- // Scanner input=new Scanner(System.in);
- System.out.print("Would you like to convert another date? ");
- char c = input.next().charAt(0);
- if("y".equals(c)){
- continue;
- }
- if("n".equals(c)){
- System.out.print("Program terminated normally.");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement