|
Hi
my program is working without any error
"it sorts an array in descending order then lists the ordered array with the original position of its value "
But i want to use the input and output as files.
i mean that , statement
int [] in1 = { 0,0,0,80,0,0,100,0,0,90,0,0,70,60};
must be as follow
int [] in1 = function that open saved file contains values so we can create an array
also i want save the output ( only the posistions of the values)
in a file (one value in each line)so it can be used by another program
i hope that any one of you can help me
thanks in advance
/******************************************************************/
import java.util.*;
public class Open {
public static void main (String [] args) {
int [] in1 = { 0,0,0,80,0,0,100,0,0,90,0,0,70,60};//input
ArrayList Values = new ArrayList();
HashMap OriginalPosition = new HashMap();
for (int i=in1.length-1; i>=0; i--) {
OriginalPosition.put(new Integer(in1),new Integer(i+1));
Values.add(new Integer(in1));
}
// Sort incoming array
Collections.sort(Values);
// List out sorted values in reverse order, with position numbers
for (int i=Values.size()-1; i>=4; i--) {
int val = ((Integer)(Values.get(i))).intValue();
System.out.print("" + val + " ");
System.out.println(OriginalPosition.get(new Integer(val))); //output
}
}
}
|
|
|
|
|
|
|
|