-
Notifications
You must be signed in to change notification settings - Fork 39
/
pattern&sum.java
52 lines (43 loc) · 1.42 KB
/
pattern&sum.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
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
class menu
{
public static void main(String args[])throws IOException
{
InputStreamReader in= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(in);
int ch;
System.out.println("menu");
System.out.println("1. 0,3,8,15,24,.........n terms");
System.out.println("2. s=1/2 + 3/4 + 5/6 + 7/8.......19/20");
System.out.println(" enter user choice ");
ch=Integer.parseInt(y.readLine());
switch(ch)
{
case 1:
{
int n,i,s=3,p=0;
System.out.println("enter the number of terms");
n=Integer.parseInt(y.readLine());
for(i=0;i<n;i++)
{
p=p+s;
s=s+2;
System.out.print(p+",");
}
}
break;
case 2:
{
int i,a=2;double s=0.00;
for(i=1;i<=19;i+=2)
{
s=s+i/a;
a=a+2;
}
System.out.println("sum= "+s);
}
Default :
System.out.println(" ");
}
}
}