-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindTheGreatestOrSmallestNumber.java
54 lines (52 loc) · 1.31 KB
/
FindTheGreatestOrSmallestNumber.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
53
54
import java.util.*;
class FindTheGreatestOrSmallestNumber{
static int a, b, c, d, p;
static String e;
Scanner sc=new Scanner(System.in);
void getData(){
System.out.println("Enter The First Number:\t");
a=sc.nextInt();
System.out.println("Enter The Second Number:\t");
b=sc.nextInt();
System.out.println("Enter The Third Number:\t");
c=sc.nextInt();
System.out.println("Please enter S for smallest number And L for largest number:\t");
e=sc.next();
}
int smallestNumber(){
p++;
if ((a<b)&&(a<c))
d=a;
else if ((b<a)&&(b<c))
d=b;
else
d=c;
return d;
}
int greatestNumber(){
p=p+2;
if ((a>b)&&(a>c))
d=a;
else if ((b<a)&&(b>c))
d=b;
else
d=c;
return d;
}
void putData(){
if (p==1)
System.out.println("The smallest number of three given numbers is:\t"+d);
if (p==2)
System.out.println("The largest number of three given numbers is:\t"+d);
}
public static void main(String[] args){
FindTheGreatestOrSmallestNumber fn=new FindTheGreatestOrSmallestNumber();
System.out.println("This application generates the largest or smallest of three given numbers");
fn.getData();
if ((e.equals("s"))||(e.equals("S")))
fn.smallestNumber();
else if ((e.equals("l"))||(e.equals("L")))
fn.greatestNumber();
fn.putData();
}
}