-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranchingLooping.java
More file actions
49 lines (44 loc) · 920 Bytes
/
BranchingLooping.java
File metadata and controls
49 lines (44 loc) · 920 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
public class BranchingLooping
{
public static void main(String[] args)
{
int i,j,a,n;
// n for taking input
// a for switch case
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number:");
n=sc.nextInt();
String c;
int fact=1;
do{
System.out.println("Enter your choice:");
System.out.println("1:Factorial \n 2:Pattern");
a=sc.nextInt();
switch(a)
{
case 1:
for(i=1; i<=n; i++)
{
fact=fact*i;
}
System.out.println("Factorial of "+n+"= "+fact);
break;
case 2:
for(i=1; i<=n; i++)
{
for (j=1; j<=i ;j++ ) {
System.out.print("#");
}
System.out.print("\n");
}
break;
default:
System.out.println("Enter correct choice from given.");
}
System.out.println("YOU want to continue?? [y/n]");
c=sc.next();
}
while(c.equals("y"));
}
}