forked from sPredictorX1708/Ultimate-Java-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaLoops.java
More file actions
25 lines (19 loc) · 946 Bytes
/
JavaLoops.java
File metadata and controls
25 lines (19 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
class JavaLoops {
public static void main (String args[]) {
int a = 1; // Assign a starting value to variable 'a'
// Demonstrating Usage of While Loop in Java
System.out.print("***** Using While Loop ****** ");
// While the value of Variable a < = 10 do the condition in the loop body { do this }
while( a <= 10) {
System.out.println("Value of a : " + a); // While the loop condition is satisfied print value of 'a'
a++; // Increment the value of 'a' for every iteration
}
// Demonstrating Usage of For Loop in Java
// Print the values that are in the range of the condition given in the loop.
System.out.print("***** Using For Loop ****** ");
for( a = 0 ; a<=10 ; a++ ) {
System.out.println("Value of a : " + a); // While the loop condition is satisfied print value of 'a'
}
}
}