Java find output programs
- Java find output programs (Data Types) | set 1
- Java find output programs (Data Types) | set 2
- Java find output programs (Data Types) | set 3
- Java find output programs (Operators) | set 1
- Java find output programs (Operators) | set 2
- Java find output programs (Operators) | set 3
- Java find output programs (if else) | set 1
- Java find output programs (if else) | set 3
- Java find output programs (switch case) | set 1
- Java find output programs (switch case) | set 2
- Java find output programs (switch case) | set 3
- Java find output programs (Loops) | set 1
- Java find output programs (Loops) | set 2
- Java find output programs (Loops) | set 3
- Java find output programs (Arrays) | set 1
- Java find output programs (Arrays) | set 2
- Java find output programs (Arrays) | set 3
- Java find output programs (this Keyword) | set 1
- Java find output programs (final Keyword) | set 1
- Java find output programs (final Keyword) | set 2
- Java find output programs (static Keyword) | set 1
- Java find output programs (static Keyword) | set 2
- Java find output programs (Parameter Passing) | set 1
- Java find output programs (Class and Objects) | set 1
- Java find output programs (Class and Objects) | set 2
- Java find output programs (Class and Objects) | set 3
- Java find output programs (Constructor & Destructor) | set 1
- Java find output programs (Constructor & Destructor) | set 2
- Java find output programs (Constructor & Destructor) | set 3
- Java find output programs (Inheritance) | set 1
- Java find output programs (Inheritance) | set 2
- Java find output programs (Inheritance) | set 3
- Java find output programs (Interface) | set 1
- Java find output programs (Interface) | set 2
- Java find output programs (Interface) | set 3
- Java find output programs (Overloading) | set 1
- Java find output programs (Overloading) | set 2
- Java find output programs (Overriding) | set 1
- Java find output programs (Overriding) | set 2
- Java find output programs (Overriding) | set 3
- Java find output programs (Exception Handling) | set 1
- Java find output programs (Exception Handling) | set 2
- Java find output programs (Exception Handling) | set 3
- Java find output programs (Enumeration) | set 1
- Java find output programs (Enumeration) | set 2
- Java find output programs (Autoboxing & Unboxing) | set 1
- Java find output programs (Autoboxing & Unboxing) | set 2
- Find output programs (Java String class)
- Find Output of Java program - 1 (Mixed topics)
- Find Output of Java program - 2 (Mixed topics)
- Java find output programs (if else) | set 2
Answer Question 1:
Output:
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point of the program.
In the main() method, we created two local variables i and num that are initialized with 0. Here, we used a while loop, that will execute till the value of the variable i is less than 5.
Now look to iterations:
Iteration1: i=0, num=0 and condition is true. num = 1*1*2+1; num = 2+1; num = 3; Then variable 'i' becomes 2 because of pre and post increment operator. Iteration2: i=2, num=3 and condition is true. num = 3*3*2+1; num = 18+1; num = 19; Then variable 'i' becomes 4 because of pre and post increment operator. Iteration3: i=4, num=19 and condition is true. num = 5*5*2+1; num = 27+1; num = 29; Then variable 'i' becomes 6 and condition will be false and program gets terminated.
Answer Question 2:
Output:
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point of the program.
In the main() method, we created two local variables i and num that are initialized with 0. Here, we used a while loop, that will execute till the value of the variable i is less than 5.
Now look to iterations:
i=0, num=0 and condition is true. Variable 'i' will increase using pre-increment operator then it will be 1. num += (1*1+1); num += (1+1); num = num + 2; num = 0+2; num = 2; Then variable 'i' becomes 1 and num will 2. Iteration2: i=1, num=2 and condition is true. Variable 'i' will increase using pre-increment operator then it will be 2. num += (2*2+4); num += 8; num = 2 + 8; num = 10; Iteration3: i=2, num=10 and condition is true. Variable 'i' will increase using pre-increment operator then it will be 3. num += (3*3+9); num += 18; num = 10 + 18; num = 28 Iteration4: i=3, num=28 and condition is true. Variable 'i' will increase using pre-increment operator then it will be 4. num += (4*4+16); num += 32; num = 28 + 32; num = 60; Iteration4: i=4, num=60 and condition is true. Variable 'i' will increase using pre-increment operator then it will be 5. num += (5*5+25); num += 50; num = 60 + 50; num = 110; Then condition will false and loop gets terminated.
Answer Question 3:
Output:
Explanation:
The above program will generate syntax error because the highest value of the byte variable is 255 but we assigned 260 which is the out of the limit of the byte that's why error gets generated.
Answer Question 4:
Output:
Explanation:
The above program will print "India" 4 times on the console screen. Here we created a variable LOOP initialized with 0.
while (false==false)
In the above-given loop condition, we checked "false==false" then the condition will always true, but we used a break statement to terminate the loop. We increased the value of the variable LOOP using pre-increment operator when the value of the variable LOOP reaches to 5, then the loop will be terminated.
Answer Question 5:
Output:
Explanation:
The above program will generate syntax error because we cannot use int value in the condition of the while loop, in Java we need to use the Boolean value in while loop condition.
need an explanation for this answer? contact us directly to get an explanation for this answer