What is the output of the below program?public class Main{ public static void main(String[] args) { int a = 25; if(a > 5) System.out.print("Hi "); if(a < 20) System.out.print("Hello "); else System.out.print("Know Program "); }}
Question
What is the output of the below program?public class Main{ public static void main(String[] args) { int a = 25; if(a > 5) System.out.print("Hi "); if(a < 20) System.out.print("Hello "); else System.out.print("Know Program "); }}
Solution
The output of the program will be "Hi Know Program".
Here's the step by step explanation:
-
The program starts with defining an integer variable 'a' with a value of 25.
-
The first 'if' statement checks if 'a' is greater than 5. Since 25 is greater than 5, it prints "Hi ".
-
The second 'if' statement checks if 'a' is less than 20. Since 25 is not less than 20, it skips printing "Hello ".
-
The 'else' statement corresponds to the second 'if' statement. Since 'a' is not less than 20, it goes to the 'else' part and prints "Know Program ".
So, the final output is "Hi Know Program".
Similar Questions
What is the output of this program? class A {public static void main(String args[]){ int var1 = 5; int var2 = 6; if ((var2 = 1) == var1)System.out.print(var2);else System.out.print(++var2); }}ans. 2314 Previous Marked for Review Next
e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}
What is the output of the program below? public static void main(String[] args) { int x = 0; while (x < 10) { if (x & 2 == 0) { System.out.print(x + “ “); } x++; } } Note: Simply type the output. No explanation whatsoever.
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
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.