所以我正在处理的代码看起来像这样
import java.util.Scanner;
public class ReadStrings{
public static String main(String[] args) {
Scanner in = new Scanner(new File("input3.txt"));
String [] array = new String[100];
int nextSpot = 0;
while( in.hasNext()){
array[nextSpot++] = in.next();
}
//use the sort function
selectionSort(array, nextSpot);
//print the results
}
public static void selectionSort(String [] array, int nextSpot){
String tmp;
for (int i = 0; i < nextSpot; i++) {
for (int j = i + 1; j < nextSpot; j++) {
if( array[i].equals(array[j])){
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
}
}
假设文本文件存在我的代码有问题吗?我也不知道如何打印结果数组