Computer Science, asked by yoge2390, 1 year ago

Write a program in java for week of the day (if else)

Answers

Answered by 123032
17
public class abc
{
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 ") ;
}
}

yoge2390: thank you so much sir but why is a= 3 written
123032: you can write any number
123032: it is your choice
yoge2390: thank you sir
123032: Sorry I am not sir
Answered by BrainlyPromoter
5

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

Attachments:
Similar questions