The goal is to have a sorted input.txt such as:
1 one
2 two
4 four
10 ten
From an input.txt of:
2 two
4 four
1 one
10 ten
So far in my code I have sorted the number array and now I have to change the String array since it's paired with the num array. How do I do that?
import java.util.*;
import java.io.*;
//Noah Cavazos
public class SortingNumbers{
public static void main(String[] args) throws FileNotFoundException {
Scanner fin = new Scanner(new File("input.txt"));
int[] nums = new int[100];
String[] texts = new String[100];
int cnt = 0;
while(fin.hasNextInt()){
nums[cnt] = fin.nextInt();
texts[cnt] = fin.nextLine();
cnt++;
}
int[] Numbers = new int[cnt];
String[] Words = new String[cnt];
for(int i = 0; i < Numbers.length; i++){
Numbers[i] = nums[i];
Words[i] = texts[i];
//System.out.println(Numbers[i] + Words[i]);
}
Arrays.sort(Numbers);
//Arrays.sort(Words); < Alphabetically
}
}