It's to take the day on the 1st Jan of the year,then output the day on any other date of the year.The same input is giving me two different output when I try it twice.Please help!(In BlueJ,we dont need the main function,I can create objects using the interface)
import java.io.*;
public class DateDay
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
int d,m,y,tot=0,cd,a=0,e,b;
String str;
char arr[]=new char[10];
String x;
public void run()throws IOException
{
System.out.println("Enter the day");
d=Integer.parseInt(br.readLine());
System.out.println("Enter the month");
m=Integer.parseInt(br.readLine());
System.out.println("Enter the year");
y=Integer.parseInt(br.readLine());
System.out.println("Enter the day on 1st");
x=br.readLine();
switch(m)
{
case 1:
tot+=d;
break;
case 2:
tot+=(31+d);
break;
case 3:
if(y%4==0)
{tot+=(31+29+d);}
else{
tot+=(31+28+d);
}break;
case 4:
if(y%4==0)
{tot+=(31+29+31+d);
}
else{
tot+=(31+28+31+d);
}
break;
case 5:
if(y%4==0)
{tot+=(31+29+31+30+d);
}
else{
tot+=(31+28+31+30+d);
}
break;
case 6:
if(y%4==0)
{tot+=(31+29+31+30+31+d);
}
else{
tot+=(31+28+31+30+31+d);
}
break;
case 7:
if(y%4==0)
{tot+=(31+29+31+30+31+30+d);
}
else{
tot+=(31+28+31+30+31+30+d);
}
break;
case 8:
if(y%4==0)
{tot+=(31+29+31+30+31+30+31+d);
}
else{
tot+=(31+28+31+30+31+30+31+d);
}
break;
case 9:
if(y%4==0)
{tot+=(31+29+31+30+31+30+31+31+d);
}
else{
tot+=(31+28+31+30+31+30+31+31+d);
}
break;
case 10:
if(y%4==0)
{tot+=(31+29+31+30+31+30+31+31+30+d);
}
else{
tot+=(31+28+31+30+31+30+31+31+30+d);
}
break;
case 11:
if(y%4==0)
{tot+=(31+29+31+30+31+30+31+31+30+31+d);
}
else{
tot+=(31+28+31+30+31+30+31+31+30+31+d);
}
break;
case 12:
if(y%4==0)
{tot+=(31+29+31+30+31+30+31+31+30+31+30+...
}
else{
tot+=(31+28+31+30+31+30+31+31+30+31+30+d...
}
break;
}
cd=tot%7;
if(x=="Sun")
a=1;
else if(x=="Mon")
a=2;
else if(x=="Tue")
a=3;
else if(x=="Wed")
a=4;
else if(x=="Thu")
a=5;
else if(x=="Fri")
a=6;
else if(x=="Sat")
a=7;
b=a+cd;
if(b>7)
e=b-7;
else
e=b;
switch(e)
{
case 1:
System.out.println("Sumday");
break;
case 2:
System.out.println("Monday");
break;
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday");
break;
case 5:
System.out.println("Thursday");
Tags: