-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntArray.java
More file actions
47 lines (46 loc) · 1.23 KB
/
IntArray.java
File metadata and controls
47 lines (46 loc) · 1.23 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
44
45
46
47
import java.util.Scanner;
import java.util.*;
public class IntArray
{
private int[] intArray;
public void GetInput()
{
Scanner input = new Scanner(System.in);
System.out.println("How numbers? (at most 50)");
intArray = new int[input.nextInt()];
System.out.println("Enter numbers");
for(int i = 0; i < intArray.length; i++)
{
System.out.print((i+1)+": ");
intArray[i] = input.nextInt();
}
}
public void Sort()
{
for(int i=0; i<intArray.length; i++)
intArray[i] = (intArray[i]*-1);
Arrays.sort(intArray);
for(int i =0; i<intArray.length; i++)
intArray[i] = (intArray[i] * -1);
}
public void GetTable()
{
int count = 1;
System.out.printf("Number Count\n");
for (int i = 0; i < intArray.length; i++)
{
if (i < intArray.length - 1)
{
if (intArray[i] == intArray[i + 1])
count++;
}
else
System.out.printf("%6d%6d\n", intArray[i], count);
if (i < intArray.length - 1 && intArray[i] != intArray[i + 1])
{
System.out.printf("%6d%6d\n", intArray[i], count);
count = 1;
}
}
}
}