Knowee
Questions
Features
Study Tools

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);  }

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

Solution

The output of the code will be 0.08828125.

Here's the step by step explanation:

  1. The initial value of num is 9032 and val is 0.5. i is 5.
  2. The do-while loop starts. Inside the loop, num is multiplied by val and i is multiplied by 10.
  3. After the first iteration, num becomes 4516 (9032 * 0.5) and i becomes 50 (5 * 10).
  4. The loop continues because i (50) is still less than 9032.
  5. After the second iteration, num becomes 2258 (4516 * 0.5) and i becomes 500 (50 * 10).
  6. The loop continues because i (500) is still less than 9032.
  7. After the third iteration, num becomes 1129 (2258 * 0.5) and i becomes 5000 (500 * 10).
  8. The loop continues because i (5000) is still less than 9032.
  9. After the fourth iteration, num becomes 564.5 (1129 * 0.5) and i becomes 50000 (5000 * 10).
  10. The loop stops because i (50000) is now greater than 9032.
  11. The final value of num (564.5) is printed out.

This problem has been solved

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

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.