import java.io.*; import java.util.*; public class Lab16 { private static String names[]; private static int fileSize; public static void main(String args[]) throws IOException { System.out.println("LAB 16! \n\n"); System.out.println(); System.out.println("Contents of Names1"); names = new String[33]; readFile("Names1.txt"); displayArray(); sortArray(); displayArray(); writeFile("Names2.txt"); } public static void readFile(String fileName) throws IOException { int k = 0; ExpoInFile f = new ExpoInFile("Names1.txt"); names[k] = f.readString(); k++; while(k <= 32) { names[k] = f.readString(); k++; } f.closeFile(); } public static void displayArray() { for(int i = 0; i <= 32; i++) { System.out.println(names[i]); } } public static void writeFile(String n) throws IOException { ExpoOutFile t = new ExpoOutFile(n); for(int q = 0; q <= 32; q++) { t.writelnString(names[q]); } t.closeFile(); } public static void sortArray() { System.out.println(); System.out.println("============================================================="); System.out.println("Alphabetical:"); System.out.println(); Arrays.sort(names); } }
my code for java class, it's probably stupid. play with it so you figure out how it works. it's been put on here as a purely "collaborative" learning effort
Wednesday, May 4, 2011
Lab16
Subscribe to:
Posts (Atom)