THanks~
this is the example and my quote are below
Write a program in JAVA that allows the user to input 5 ints. The program will then output these five values in reverse order. The program will then output the values in order with a statement on how many of the remaining values are larger, smaller, or equal.
Example 1:
Input:
1
2
3
4
5
Output:
5
4
3
2
1
1 - 4 larger, 0 smaller, 0 equal
2 - 3 larger, 2 smaller, 0 equal
3 - 2 larger, 2 smaller, 0 equal
4 - 1 larger, 3 smaller, 0 equal
5 - 0 larger, 4 smaller, 0 equal
and my qupte are as follow but i am lose in how to
count how many int are greater/less/equals then the currenty index int in a array. everytime the max value changes. Not sure how to make the max constant after it find the max int number in the array.
public static void main( String[] args )
{
Scanner scan = new Scanner(System.in);
int[] numbers = new int[5];
for(int index = 0 ; index < numbers.length; index ++)
{
System.out.print("enter number"+(index + 1) + " : ");
numbers[index] = scan.nextInt();
}
for (int j=0; j <= (numbers.length -1) ;j++)
int small = 0;
int greater = 0;
int count= 0;
for (int n=(numbers.length -1); n>=0 ; n--)
if (numbers[j] > numbers[n])
{
greater++;
}
else if (numbers[j] < numbers[n])
{
small++;
}
else if (numbers[j] == numbers[n])
{
count++;
}
System.out.println(+values[j]+": " + greater+ "greater: "
+small+ "smaller: " +count+ "equal" );