Hello,
i'm a new member here in this forum..
and i think lot of programmers may help me here..
i'm a newbie also in java programming..
my teacher wants us to make a program that accepts 5 integers and then arrange it from highest to lowest..
i have an idea how to do it but it is on a hard way.. my teacher wants us to do it in a short way.. i dont have much idea in doing it on that way.. (because my logic is POOR..T-T)
but i tried my best i try to figure out last night until now i cant get it.. here's my code..
/**
* @(#)highest.java
*
* highest application
*
* @o0sample0o
* @version 1.00 2009/11/24
*/
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
public class highest {
public static void main(String[] args) {
JTextArea myTextArea = new JTextArea(5,10);
JScrollPane myScrollBar = new JScrollPane(myTextArea);
int number[], first=0, second=0, third=0,fourth=0,fifth=0;
for( int x=1;x<=5;x++)
{
number[x] = Integer.parseInt(JOptionPane.showInputDialog("Enter Number"+x+": "));
}
if(number[1]>first)
{
first=number[1];
}
else if(number[2]>second)
{
second=number[2];
}
else if(number[3]>third)
{
third=number[3];
}
else if(number[4]>fourth)
{
fourth=number[4];
}
else
{
fifth=number[5];
}
myTextArea.setText("The 1st largest is: "
+first+"\nThe 2nd largest is: "
+second+"\nThe 3rdnd largest is: "
+third+"\nThe 4th largest is: "
+fourth+"\nThe 5th largest is: "
+fifth);
JOptionPane.showMessageDialog(null, myScrollBar);
System.exit(0);
}
}
oh.. and one more question..
i try to use an one dimensional array..
i there anyway to execute it here in java? i have small knowledge in c++.. so i think the syntax here in java have lot different on c++?
thanks for reading my problem..
Thanks DANIWEB!:)