Note that there are some explanatory texts on larger screens.

plurals
  1. POJava quick sort, reading from a user input file into any array (to be sorted)
    primarykey
    data
    text
    <p>What's up y'all,</p> <p>I am trying to write some code in Java that will read in the numbers from a file (one # on each line of .txt file) put them into an array, and then run quick sort on the array. Eclipse is showing some red that I am having trouble with. My errors are marked with comments, and what the error is, if anyone can help me get this to run, thanks everyone!</p> <p>-Kyle</p> <p>OK, I updated with the first two answers, Thanks so far, but two more errors Im not really understanding. </p> <pre><code>import java.io.*; import java.util.Scanner; import java.io.BufferedReader; import java.io.File; public class Lab3 { public static void main(String[] args) throws IOException{ System.out.print("Name of file with array: "); Scanner readIn = new Scanner(System.in); String input=readIn.nextLine();} **testScan1(input);** //Return Type for method is missing (but I am trying to call the method here) public static void testScan1(String filename) { File file = new File(filename); Scanner scan; int [] array = new int[5]; try{ scan = new Scanner( file ); } catch ( java.io.FileNotFoundException e ) { System.out.println( "couldn't open. file not found " ); return; } while(scan.hasNext()) { for( int i = 0; i &lt;= file.length(); ++i) { **array[i]=scan.next();** /*Type mismatch, cannot convert from sting to int. (I moved the declaration about try?)*/ } int partition(int arr[], int left, int right) { int i=left; int j = right; int tmp; int pivot = arr[(left+right)/2]; while (i&lt;=j){ while(arr[i]&lt;pivot) i++; while (arr[j]&gt;pivot) j--; if (i&lt;=j){ tmp=arr[i]; arr[i]=arr[j]; arr[j]=tmp; i++; j--; } } return i; } void quickSort(int arr[], int left, int right){ int index = partition(arr, left, right); if (left&lt;index-1); quickSort(arr, left, index-1); if (index&lt;right) quickSort(arr, index, right); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload