Question
What is the output of the following Java code? Â
 public class LoopTest {     public static void main(String[] args) {       int x = 0;       while (x < 5) {         x++;         if (x == 3) {           break;         }       }       System.out.println(x);     }   }Solution
Initial: x = 0 Â Â Loop 1: x < 5 (0 < 5) is true. x becomes 1. x == 3 (1 == 3) is false. Â Â Loop 2: x < 5 (1 < 5) is true. x becomes 2. x == 3 (2 == 3) is false. Â Â Loop 3: x < 5 (2 < 5) is true. x becomes 3. x == 3 (3 == 3) is true. break executes. Â Â The loop terminates. System.out.println(x) prints 3.
"A boat takes 60 seconds to travel ______ metres downstream and 40 seconds to travel ______ metres upstream in the same river. The speed of the stream i...
A boat covers 24km upstream and 36km downstream in 6 hours while it covers 36km upstream and 24km downstream in 13/2 hours. The speed of the current is....
A ship, when moving against the current, can travel a distance of 240 km in 8 hours. If the ship's speed in calm waters is 40 km/hr, how many hours will...
A boat covers a distance of 338 km upstream in 13 hours. After rain, the speed of the stream increases by 50%, and the speed of t...
If a boat travels 18 km more in downstream than in upstream in 3 hours and if the speed of the Boat in still water is 20 kmph. Find the distance tra...
A boat can travel 7.2 km upstream in 18 min. If the ratio of the speed of the boat in still water to the speed of the stream is 7:1. How much time will ...
A boat goes 52 km in upstream in 4 hours and takes 3 hours to complete a distance of 15 km in downstream. Find the speed of boat in still water.
A boat travels 150 km downstream in 6 hours. The difference between its downstream speed and upstream speed is 3 km/h. What is the ratio of the boat's s...
The speed of a boat in still water is 7 km/hr and speed of current is 4 km/hr. If time taken to cover a certain distance upstream is 22 hours, then how ...
The ratio of the speed of boats ‘A’ and ‘B’ in still water is 8:9, respectively. The speed of the current is 25% of the speed of boat ‘A’ in...