-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLoops.java
41 lines (36 loc) · 1.17 KB
/
Loops.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class Loops {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
/*
Looping Statements:- 1) While loop
2) Do-While loop
3) For loop
*/
// 1) While loop
int a,b;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter Second number(Should be greater then first one): ");
b = sc.nextInt();
while(b>=a){
System.out.print(a + " ");
a++;
}
// 2) Do-While loop
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter Second number(Should be less then first one): ");
b = sc.nextInt();
do{
System.out.print(a + " ");
a--;
}while(b<=a);
// 3) for loop
System.out.print("Enter number to print table: ");
a = sc.nextInt();
for(int i = 1; i <= 10 ; i++){
System.out.printf("%d x %d = %d\n",a,i,a*i);
}
}
}