OK, here is my problem. I need to take a array of Strings and sort it alphabetically and then print out the first String: For example, a string of “Georgia, Florida, Alabama”, It should print out Alabama. The Strings are not submitted by the user, i have a file with a bunch of states that is inputed as an array.
This is what I have:
import java.io.*;
import java.util.*;
public class MinString
{
private static final int SIZE = 10;
public static void main(String[] args)
{
String[] list = new String[SIZE];
int numItems;
numItems = Initialize (list);
System.out.println(numItems);
}
private static int Initialize (String[] list)
{
//post : List is initialized with all strings from file.
String filename, stateInput;
int i = 0, numItems = 0;
try {
System.out.print("Input File : ");
Scanner stdin = new Scanner(System.in);
filename = stdin.nextLine();
stdin = new Scanner(new File(filename));
while ((stdin.hasNext()) && (i < list.length))
{
stateInput = stdin.nextLine();
System.out.println("S = " + stateInput);
list[i] = stateInput;
i++;
}
numItems = i;
}
catch (IOException e) {
System.out.println(e.getMessage());
}
return numItems;
}
// Method FindMin goes here
private static String FindMin (String[] list, numItems);
?????
}
I’m not sure how to write this FindMin Method. I need to write FindMin so that it takes as input an array of size numItems of strings and returns to the calling function the minimum string.
Any ideas?
1 Answer