-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddEvenManipulate.java
More file actions
43 lines (42 loc) · 1.21 KB
/
Copy pathOddEvenManipulate.java
File metadata and controls
43 lines (42 loc) · 1.21 KB
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
import java.util.*;
class OddEvenManipulate{
static int a, b, c, e;
static float d;
static String z;
Scanner sc=new Scanner(System.in);
void oddNumbers(){
for (a=b; a<=100; a=a+2)
System.out.println("\t\t\t\t\t"+a);
d=2500;
System.out.println("The sum of first hundred odd numbers is:\t"+d);
d=d/50;
System.out.println("The average of first hundred odd number is:\t"+d);
}
void evenNumbers(){
for (a=b; a<=100; a=a+2)
System.out.println("\t\t\t\t\t"+a);
d=2550;
System.out.println("The sum of first hundred even numbers is:\t"+d);
d=d/51;
System.out.println("The average of first hundred even number is:\t"+d);
}
public static void main(String[] args){
OddEvenManipulate oem=new OddEvenManipulate();
Scanner sc=new Scanner(System.in);
System.out.println("This application gives the sum and average of odd or even numbers upto hundred");
System.out.println("Please enter O for odd numbers and E for even numbers:\t");
z=sc.next();
if ((z.equals("o"))||(z.equals("O")))
{
b=1;
oem.oddNumbers();
}
else if ((z.equals("e"))||(z.equals("E")))
{
b=0;
oem.evenNumbers();
}
else
System.out.println("Wrong input. Please try again later...");
}
}