Knowee
Questions
Features
Study Tools

rect answerWhat will be the output of the following Java program?class conditional_statements {    public static void main(String args[])     {         final int u=10,v=20;     while(u<v)     {      System.out.println("Good");     }     System.out.println("Morning");     } }

Question

rect answerWhat will be the output of the following Java program?class conditional_statements {    public static void main(String args[])     {         final int u=10,v=20;     while(u<v)     {      System.out.println("Good");     }     System.out.println("Morning");     } }

🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The program will result in an infinite loop printing "Good". This is because the condition in the while loop u<v is always true as u and v are final variables with values 10 and 20 respectively. The final keyword in Java is used to apply restrictions on class, method, and variable. Final variables cannot be changed once assigned. Hence, the condition never becomes false and "Good" is printed indefinitely. The statement System.out.println("Morning"); is never reached.

This problem has been solved

Solution 2

The program will result in an infinite loop printing "Good". This is because the condition in the while loop u<v is always true as u and v are final variables with values 10 and 20 respectively. The final keyword in Java is used to apply restrictions on class, method, and variable. Final variables cannot be changed once assigned. Hence, the value of u remains 10 and v remains 20, making the condition always true. The statement "Morning" will never be printed as the program never exits the while loop.

This problem has been solved

Similar Questions

rect answerWhat will be the output of the following Java code? class Codetantra {    public static void main(String args[]) {         try {             System.out.print("Good" + " " + 1 / 0);          }         finally {        System.out.print("Morning");                }     } }

What will be the output of the following Java program?class java   {    public static void main(String args[])    {      int var1 = 3;       int var2 = 8;      if ((var2 = 2) == var1)        System.out.print(var2);      else         System.out.print(++var2);    }   }Options3421

What will be the output of the following Java program?class mainclass { public static void main(String args[]) { boolean ct1 = true; boolean ct2 = false; if (ct1) System.out.println(ct1); else System.out.println(ct2); } }Options10truefalse

rect answerWhat will be the output of the following Java program?class java  {    public static void main(String args[])     {          int w = 5;       int x = 10;       first:        {        second:         {          third:           {             if (w == x >> 1)              break second;          }          System.out.println(w);        }        System.out.println(x);       }    }   }

Which of these is the output of the following program?int grade = 4;if(grade > 5) { System.out.println("Added water.");}else if(grade > 3) { System.out.println("Added soda.");}if(grade > 3) { System.out.println("Added ice");}if(grade > 2) { System.out.println("Added straw.");}if(grade <= 2) { System.out.println("Added lemon."); }Added soda.Added ice.Added straw.Added water.Added soda.Added ice.Added straw.Added water.Added ice.Added straw.Added water.Added soda.Added ice.Added straw.Added lemon.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.