Skip to content

Commit 2214964

Browse files
committed
feat: Print all odd numbers from 1 to 100 using for loop
🧮 Logic: - Loop from 1 to 100 - Use condition `value % 2 != 0` to filter and print odd numbers only. Signed-off-by: Somesh diwan <[email protected]>
1 parent 17ed4b9 commit 2214964

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
public class Loops
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class Loops {
2+
public static void main(String[] args) {
53
System.out.println("These are the odd numbers from 1 to 100.");
64
System.out.println("Ready?");
5+
76
//for values from 1 to 100
8-
for (int value = 1; value <= 100; value++)
9-
{
10-
System.out.println(value); //print them
7+
for (int value = 1; value <= 100; value++) {
8+
if (value % 2 != 0) {
9+
System.out.println(value);
10+
}
1111
}
1212
System.out.println("That was fast!");
1313
}
14-
}
14+
}

0 commit comments

Comments
 (0)