Question : Java quick sort, reading from a user input file into any array (to be sorted)

Hey, What's up y'all,

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 name inputted by user) 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!

-Kyle
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
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);**  /*Eclipse says "return type for method is missing" trying to call method testScan below*/ 

**public testScan1(String filename)**  //"Return type is missing for method" 
{
File file = new File(filename);
Scanner scan;
try{
 int [] array = new int[5]; 
scan = new Scanner( file );
}
catch ( java.io.FileNotFoundException e )
{
System.out.println( "couldn't open. file not found "  );
return;
}
while(file.hasNext())      //"underlies "hasNext" "Method hasNext() is undefined"
{
for( int i = 0; i <= file.length(); ++i)
{ 
**array**[i]=scan.next();    //"Array cannot be Resolved" 

}
} 
int partition(int arr[], int left, int right)
{
 int i=left; int j = right;
 int tmp;
 int pivot = arr[(left+right)/2];
 while (i<=j){
  while(arr[i]pivot)
   j--;
  if (i<=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
           

Answer : Java quick sort, reading from a user input file into any array (to be sorted)

You need to get your braces and methods right. This compiles:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
import java.io.*;
import java.io.BufferedReader;
import java.io.File; 
import java.util.Scanner; 

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();
    } 
    public static void testScan1(String filename) //"Return type is missing for method" 
     {
        File file = new File(filename);
        Scanner scan; 
        try {
            int[] array = new int[5];
            scan = new Scanner(file);
        } catch (java.io.FileNotFoundException e) {
            System.out.println("couldn't open. file not found "); 
            return;
        } 
        while (scan.hasNext()) //"underlies "hasNext" "Method hasNext() is undefined"
         {
            for (int i = 0; i <= file.length(); ++i) {
                //    **array**[i]=scan.next();    //"Array cannot be Resolved" 
            }
        }
    } 
    int partition(int[] arr, int left, int right) {
        int i = left;
        int j = right;
        int tmp;
        int pivot = arr[(left + right) / 2]; 
        while (i <= j) {
            while (arr[i] < pivot)
                i++; 
            while (arr[j] > pivot)
                j--; 
            if (i <= 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 < (index - 1)) {
            ;
        } 
        quickSort(arr, left, index - 1); 
        if (index < right) {
            quickSort(arr, index, right);
        }
    }
}
Random Solutions  
 
programming4us programming4us