I want my program to loop through the options (1,2,3) over and over again so I can perform the functions several times. However, after I type the input for one option, the program just terminates. How can I make it loop through multiple times without terminating?
This is sample input and output at the moment:
1 - Input
2 - Look up
3 - Blacklist
3
Enter Blacklisted IPA: 232
(Then terminates)
import java.util.*;
public class Main {
public static void main(String[] args) {
DNS a = new DNS();
String domain;
String ipa;
System.out.printf("1 - Input\n");
System.out.printf("2 - Look up\n");
System.out.printf("3 - Blacklist\n");
Scanner scan = new Scanner(System.in);
while ( scan.hasNextInt() ) {
int option = scan.nextInt();
if(option == 1){
System.out.printf("Enter Domain & IPA: ");
Scanner scan1 = new Scanner(System.in);
String theLine = scan1.nextLine();
String[] split = theLine.split(" ");
domain = split[0];
ipa = split[1];
a.input(domain, ipa);
scan1.close();
} else if (option == 2){
System.out.printf("Enter Domain: ");
Scanner scan2 = new Scanner(System.in);
String theLine = scan2.nextLine();
domain = theLine;
ipa = a.lookup(domain);
if(ipa.equals("null")){
System.out.printf("There is no IPA for %s\n", domain);
} else {
System.out.printf("The IPA for %s is %s\n", domain, ipa);
}
scan2.close();
} else if (option == 3){
System.out.printf("Enter Blacklisted IPA: ");
Scanner scan3 = new Scanner(System.in);
String theLine = scan3.nextLine();
ipa = theLine;
a.blacklist(ipa);
scan3.close();
} else {
System.out.printf("Incorrect command input\n");
}
}
scan.close();
}
}