import java.util.*;
import javax.swing.*;
public class Array1
{
public static int counter = 0; //global
public static void main(String[] args)
{
int NumElements = 0;
int x = 0;
String entry= "";
String ChoiceString = "";
NumElements = Integer.parseInt(JOptionPane.showInputDialog(null,
"How many elements shall I create in the array?"));
String[] TheChoices = new String[NumElements];
Arrays.fill(TheChoices, "0123456789");
TheChoices[x] = JOptionPane.showInputDialog(null,
"Enter items to add to the array. Enter \"quit\" to quit");
while(!TheChoices[x].equals("quit") && x < TheChoices.length)
{
//Accumulate the choices from the array and add a line
ChoiceString = ChoiceString + TheChoices[x] + "\n";
++x;
if(x < TheChoices.length)
{
TheChoices[x] = JOptionPane.showInputDialog(null,
"Enter items to add to the array. Enter \"quit\" to quit");
}
}
entry = JOptionPane.showInputDialog(null,
"Today's menu is\n" + ChoiceString +
"Please make a selection");
for(int z = 0; z < TheChoices.length; z++)
{
if(TheChoices[z].equals(entry))
{
JOptionPane.showMessageDialog(null,
"I found the item in the array!");
break;
}
else
{
counter = counter + 1;
}
}
if(counter == TheChoices.length)
{
JOptionPane.showMessageDialog(null,
"That item was not found.");
}
System.exit(0);
}//close main()
}//close class
|