Hello, i'm having trouble getting this program to work. It works when i just directly put in the file name, but when i try to use args and i pass it threw the command line. i can't get it to work. I've been testing stuff but i can't seem to figure it out. I use jgrasp and i have been typing in the run arguments line at the top of the program box. If anyone could give me a clue as to why it won't even compile and its saying it cannot find args
// SortDoubleFromFile.java
import java.io.*;
import java.util.*;
public class SortDoublesFromFile
{
public static void main(String[] args)throws IOException
{
// O = Orginal
// S = Sorted
double[] Onum = new double[100];
double[] Snum = new double[100];
int sizeN = ReadFile(Onum, Snum);
Sorter(sizeN, Snum);
PrintResults(sizeN, Onum, Snum);
}
public static int ReadFile( double[] Onum, double[] Snum)throws IOException
{
Scanner fileScan = new Scanner(new File( args[0]));
int count = 0;
while( fileScan.hasNextDouble())
{
double number = fileScan.nextDouble();
Onum[count] = number;
Snum[count] = number;
count++;
}
fileScan.close();
return count;
}
public static void Sorter( int sizeN, double[] Snum)throws IOException
{
int i = 0;
while (i < sizeN)
{
int indexOfMin = i;
int count = i+1;
while(count < sizeN)
{
if( Snum[count] < Snum[indexOfMin])
indexOfMin = count;
count++;
}
double min = Snum[indexOfMin];
Snum[indexOfMin] = Snum[i];
Snum[i] = min;
i++;
}
}
public static void PrintResults( int sizeN, double[] Onum, double[] Snum)throws IOException
{
int i = 0;
System.out.println("Orginal List");
while(i < sizeN)
{
System.out.println(Onum[i]);
i++;
}
System.out.println(" ");
i = 0;
System.out.println("Sorted List");
while(i < sizeN)
{
System.out.println(Snum[i]);
i++;
}
}
}