New To Java , I'm Stuck , Please Help!
- From: nickdundas@xxxxxxxxx
- Date: 23 Mar 2006 06:14:01 -0800
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
.
- Follow-Ups:
- Re: New To Java , I'm Stuck , Please Help!
- From: Oliver Wong
- Re: New To Java , I'm Stuck , Please Help!
- From: Rhino
- Re: New To Java , I'm Stuck , Please Help!
- From: opalpa@xxxxxxxxx opalinski from opalpaweb
- Re: New To Java , I'm Stuck , Please Help!
- Prev by Date: Re: getParentFile() method from File class problems
- Next by Date: Re: New To Java , I'm Stuck , Please Help!
- Previous by thread: Pattern extracting
- Next by thread: Re: New To Java , I'm Stuck , Please Help!
- Index(es):
Relevant Pages
|