I can't think of how to stop this infinite loop I have ran into. The assignment is to create a menu driven program and have the user enter a word into the dictionary. Then they have the choice to enter more words or check a word against the "dictionary" they have created.
import java.util.Scanner;
public class W11E1 {
public static void main(String[] args) {
Menu();
Scanner input = new Scanner (System.in);
String [] array = new String [100];
int choice = getChoice();
while (true){
if (choice == 1){
System.out.println("Enter a word into dictionary.");
for (int i = 0; i < array.length; i++){
array [i] = input.next();
if (i > array.length)
System.out.println("Limit reached.");}}
if (choice == 2){
System.out.println("Enter word to check against dictionary.");
String Word = CheckWord();
for (int i = 0; i < array.length; i++){
array [i] = Word;}}
if (choice == 3){
System.exit(0);}
Menu();
getChoice();
}
}
public static void Menu(){
System.out.println("Enter your choices corresponding number.");
System.out.println("1. Enter a dictionary word.");
System.out.println("2. Check a word against the dictionary.");
System.out.println("3. Quit.");
}
public static int getChoice(){
Scanner input = new Scanner (System.in);
int choice = input.nextInt();
return choice;
}
public static String CheckWord(){
Scanner input = new Scanner (System.in);
String Word = input.next();
return Word;
}
}