When I compile the program below I get the message "variable x may not have been initialized" yet as far as I see I did. I am trying to have a program where a person selects a number from 1 to 10 and it then shows the corresponding string from the array.
import java.util.*;
import javax.swing.*;
public class JavaArray
{
public static void main(String[] args)
{
String[] topJava = {"Challenging", "Fun", "Computer stuff",
"Learning new stuff", "Interesting", "Make my own programs",
"Solve my own problems", "Have jgrasp to help", "Lots of books to help", "Tutorials online to help"};
String[] choicesString = new String[10];
String strSelectedJava;
int selectedJava;
int x;
strSelectedJava = JOptionPane.showInputDialog(null,
"Choose a number between 1 and 10");
selectedJava = Integer.parseInt(strSelectedJava);
selectedJava = x;
x = Arrays.binarySearch(topJava, selectedJava);
if(x >= 0 && x < selectedJava)
JOptionPane.showMessageDialog(null, "One reason I
like Java is:\n" + topJava);
else
JOptionPane.showMessageDialog(null,
"Sorry - That number is not between 1 and 10");
System.exit(0);
}
}