New To Java , I'm Stuck , Please Help!



Hello,

I just started JAVA @ the university Level and as the semester is
coming to a close , the last assignment is proving to be tough for me
and I would greatly appeciate any help solving my problem. Anyways
this is the assignment,

"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
"

Ok so basically I have got everything up to the reverse order working ,
I even have the final loop set up which goes through the array and
formats the output to appear like this
"
[0] - 0 larger, 0 smaller, 0 equal
[1] - 0 larger, 0 smaller, 0 equal
[2] - 0 larger, 0 smaller, 0 equal
[3] - 0 larger, 0 smaller, 0 equal
[4]- 0 larger, 0 smaller, 0 equal

I can't figure out how to get the larger, smaller, equal part to work
and I've tried for many hours=S I'll post what I have so far.

import java.util.*;

public class ReverseOrder
{
public static void main (String[] args)
{

int larger = 0;
int smaller = 0;
int equals = 0;

Scanner scan = new Scanner (System.in);

int[] numbers = new int[5];
int[] check = new int[5];

for(int index=0; index < numbers.length; index++)
{
System.out.print ("Enter Number" + (index+1) + ":");
numbers[index] = scan.nextInt();
check[index] = numbers[index];
}



System.out.println ("The numbers in reverse order:");



for (int index=numbers.length-1; index >= 0; index--)
{
System.out.print (numbers[index] + " " + "\n");
}

for(int index=0; index < numbers.length; index++)
System.out.print (numbers[index] + " " + " Smaller " +
(smaller) + " Larger " + (larger) + " Equals " + (equals) + "\n");
}

}

Please let me know if you can help because I'm getting a major
headache! Thanks for your time.

Nick

.



Relevant Pages

  • Re: New To Java , Im Stuck , Please Help!
    ... the last assignment is proving to be tough for me ... "Write a program in JAVA that allows the user to input 5 ints. ... int smaller = 0; ... I think many professional programmers would use the Collections classes to ...
    (comp.lang.java.help)
  • Re: Question about ++
    ... I have got a question about the post increment operator. ... It seems int he code above the ++ is completly disregarded ... Java completely evaluates the right hand side of an assignment before ... Do the assignment, setting i to the right hand side result, 1. ...
    (comp.lang.java.programmer)
  • Help: "Assignment makes integer from pointer without a cast"
    ... Im working on an assignment in c (which im not very familiar with at all, ... since I prefer java). ... assignment makes integer from pointer without a cast". ... int main ...
    (comp.lang.c)
  • Re: what is the right value about a = a++;
    ... int a = 0, b; ... a equals 1. ... follows that Java sucks ...
    (comp.lang.c)
  • Re: Why is concept of equals and operator== implemented this way?
    ... or calling virtual methods internally. ... compiler generate a call to .Equals for? ... public static bool operator!= ... public override int GetHashCode() ...
    (microsoft.public.dotnet.languages.csharp)