Write a program in java for week of the day (if else)
Answers
{
public static void main(String []args)
{
int a=3;
if(a==1)
System. out. println ("Day is Sunday ") ;
else if(a==2)
System. out. println(" Day is Monday ") ;
else if(a==3)
System. out. println (" Day is Tuesday") ;
else if(a==4)
System. out. println ("Day is Wednesday ") ;
else if (a==5)
System. out. println (" Day is Thursday ") ;
else if (a==6)
System. out. println (" Day is Friday ") ;
else if (a==7)
System. out. println (" Day is Saturday ") ;
else
System. out. println (" Wrong number entered ") ;
}
}
Sample program to find out the finding which day of the week is it using the number entered by user(Switch Case):
public class Brainly
{
public static void main(int b)
{
System.out.println("Entered day of the week: "+b);
switch(b)
{
case 1:
{
System.out.println("Monday");
break;
}
case 2:
{
System.out.println("Tuesday");
break;
}
case 3:
{
System.out.println("Wednesday");
break;
}
case 4:
{
System.out.println("Thursday");
break;
}
case 5:
{
System.out.println("Friday");
break;
}
case 6:
{
System.out.println("Saturday");
break;
}
case 7:
{
System.out.println("Sunday");
break;
}
default:
System.out.println("Wrong input.");
}
}
}
Output:
Entered day of the week: 5
Friday
Sample program to find out the finding which day of the week is it using the number entered by user(If else if Ladder):
public class Brainly
{
public static void main(int b)
{
System.out.println("Entered day of the week: "+b);
if(b==1) System.out.println("Monday");
else if(b==2) System.out.println("Tuesday");
else if(b==3) System.out.println("Wednesday");
else if(b==4) System.out.println("Thursday");
else if(b==5) System.out.println("Friday");
else if(b==6) System.out.println("Saturday");
else if(b==7) System.out.println("Sunday");
else System.out.println("Wrong input.");
}
}
Output:
Entered day of the week: 5
Friday