-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind the lowest and highest level of numbers.txt
64 lines (55 loc) · 1.36 KB
/
Find the lowest and highest level of numbers.txt
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
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
class Program{
static int[] sarr;
public static void main(String args[]){
int count=0;
int[] arr = {2, 4, 5, 3, 8, 7, 9, 6, 1};
for (int a : arr)
count++;
sarr = new int[count];
System.out.println(find(desc(arr, 0), count));
}
public static int[] desc(int[] arr, int index){
int count=0, max=0;
for (int a : arr)
count++;
int noOfI=0;
for (int i=0; i<count; i++){
if (arr[i] > max){
max = arr[i];
noOfI = i;
}
}
sarr[index] = max;
arr[noOfI] = 0;
index++;
int breakCount=0;
for (int i=0; i<count; i++){
if (arr[i] == 0)
breakCount++;
}
if (breakCount == count)
return sarr;
else
desc(arr, index);
return sarr;
}
public static int find(int a[], int totalNumbers){
int returnValue=0;
Scanner inputChar = new Scanner(System.in);
System.out.print("Want to find the Lowest or Highest (L/H): ");
char c = inputChar.next().charAt(0);
Scanner inputInt = new Scanner(System.in);
System.out.print("Enter Level of Number you want to find: ");
int level = inputInt.nextInt();
if (c == 'L' || c == 'l'){
returnValue = a[totalNumbers - level];
}
else if (c == 'H' || c == 'h'){
returnValue = a[level - 1];
}
else
System.out.println("Wrong Input!!!");
return returnValue;
}
}