Hi, im currently studying for my final test in java beginner class, so there is a problem that i couldn't solved until now, i'm totally beginner and have search the solution for almost two days :(
The program is taking variabel n from other text file, then this n will be used as the amount of randomize data, after we get the random array we need to sort and reserve it, so far i could make the sort but not with the reverse, please somebody give a solution what should i do to make a reserve/descendant int array in output
import java.io.FileInputStream;
import java.util.*;
public class SortReserve{
public static void main(String []args) throws Exception{
Scanner input = new Scanner(System.in);
Random rnd= new Random();
Scanner fs;
int deret;
String filename;
int n;
System.out.print ("Nama File : "); filename = input.nextLine();
try {
fs = new Scanner (new FileInputStream(filename));
while (fs.hasNext()){
n=fs.nextInt();
System.out.printf("\n N : %d%n\n",n);
int [] menaik = new int [n];
for(int i=0;i<menaik.length;i++){
menaik[i]=(rnd.nextInt(100)+1);
Arrays.sort( menaik );
System.out.println("Menaik\n");
System.out.printf("%5d ",menaik[i]);
}System.out.println("\n");
}
fs.close();
}
catch (java.io.FileNotFoundException e){
System.err.println ("Can't make the file "+ filename);
System.exit(-1);
}
catch (SecurityException e){
System.err.println("Accses denied");
System.exit(-1);
}
}
}
I've tried compare and just found out it only works for string array, i've search how to convert int array to string but didn't work out, any help and solution really appreciated :)
NB : you need any text file contains a number when running this program