Skip to content

Commit 46332c3

Browse files
committed
feat: Simulate cooling process using break and continue to detect ice formation
🧠 Logic: - Start with water at 100°C and reduce temperature by 5°C each loop. - If temperature > 40°C, print warning and `continue` to next iteration (skip thermometer reading). - Once temperature reaches 0°C or below, print "We have ice!" and `break` the loop. 🎯 Focus: Demonstrates control flow using `continue` to skip early output and `break` to stop once ice forms. Signed-off-by: Somesh diwan <[email protected]>
1 parent b5802a8 commit 46332c3

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
public class BreakingTheIce
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class BreakingTheIce {
2+
public static void main(String[] args) {
53
int temperature = 100;
64
int ice = 0;
75
boolean machineOn = true;
6+
87
System.out.println("Let's cool this water!");
9-
while (machineOn)
10-
{
8+
while (machineOn) {
119
temperature -= 5;
12-
if (temperature > 40)
13-
{
10+
if (temperature > 40) {
1411
System.out.println("Too hot! Thermometer unusable.");
1512
continue;
1613
}
1714
System.out.println("Temperature -> " + temperature);
18-
if (temperature <= ice)
19-
{
15+
if (temperature <= ice) {
2016
System.out.println("We have ice!");
2117
break;
2218
}
2319
}
2420
}
25-
}
21+
}

0 commit comments

Comments
 (0)