मराठी

Rewrite the following program segment using a for loop. int a = 5, b = 10; while (b>0) {b−=2; } System.out.println (a * b); - Computer Applications

Advertisements
Advertisements

प्रश्न

Rewrite the following program segment using a for loop.

     int a = 5, b = 10;

     while (b>0)

     {b−=2;

     }

     System.out.println (a * b);

कोड लेखन
दीर्घउत्तर
Advertisements

उत्तर

int a = 5, b;
for (b = 10; b > 0; b-=2) 
{
    // empty body
}
System.out.println(a * b);
  • b = 10 is moved to the first part of the for loop.
  • b > 0 remains the same in the middle.
  • The expression b-=2 is moved to the last part of the for header. Since the only action in the while loop was this update, the body of the for loop remains empty.
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×