Write the output of the below code(1 Marks)public static void main(String[] args) { double num = 9032; double val = 0.5; int i = 5; do { num *= val; i *= 10; } while ( i <= 9032 ); System.out.println(num); }
Question
Write the output of the below code(1 Marks)public static void main(String[] args) { double num = 9032; double val = 0.5; int i = 5; do { num *= val; i *= 10; } while ( i <= 9032 ); System.out.println(num); }
Solution
The output of the code will be 0.08828125.
Here's the step by step explanation:
- The initial value of
numis 9032 andvalis 0.5.iis 5. - The
do-whileloop starts. Inside the loop,numis multiplied byvalandiis multiplied by 10. - After the first iteration,
numbecomes 4516 (9032 * 0.5) andibecomes 50 (5 * 10). - The loop continues because
i(50) is still less than 9032. - After the second iteration,
numbecomes 2258 (4516 * 0.5) andibecomes 500 (50 * 10). - The loop continues because
i(500) is still less than 9032. - After the third iteration,
numbecomes 1129 (2258 * 0.5) andibecomes 5000 (500 * 10). - The loop continues because
i(5000) is still less than 9032. - After the fourth iteration,
numbecomes 564.5 (1129 * 0.5) andibecomes 50000 (5000 * 10). - The loop stops because
i(50000) is now greater than 9032. - The final value of
num(564.5) is printed out.
Similar Questions
public class Compute {public static void main (string args [ ]){int result, x ;x = 1 ;result = 0;while (x < = 10) {if (x%2 == 0) result + = x ;+ + x ;}System.out.println(result) ;}}
What is the output of the programme below?public static void main(String[] args) { int x = 0; while (x < 10) { if (x & 2 == 0) { System.out.print(x + “ “); } x++; }}
Select the correct answerWhat will be the output of the following Java program?class Output { public static void main(String args[]) { double ct1 = 3.0; double ct2 = 2.0; double ct3 = Math.pow( ct1, ct2 ); System.out.print(ct3); } }Options3.02.09.08.0
What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213
What will be the output of the program?public class Sample{ public static void main(String [] args) { int i = 10; do while ( i < 10 ) System.out.print("The value of i is " + i); while ( i > 10 ) ; }}Select one:a.The value of i is 10b.No output is produced.c.Compilation errord.The value of i is 10 The value of i is 10
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.