The below is a example of Java code of a menu structure, loop, if and else. If 1,2,3 options are chosen it goes back to the start, if option 4 is chosen it is at the end of the loop.
package kad;
import java.io.*;
import java.util.*;
public class menu {
public static void main(String[] args) {
Boolean LoopControl = true;
Scanner sc = new Scanner(System.in);
while(LoopControl)
{
System.out.println("1. Windows");
System.out.println("2. macOS");
System.out.println("3. Linux");
System.out.println("4. Exit");
String strUserInput = sc.next();
int intUserInput = Integer.parseInt(strUserInput);
if(intUserInput == 1)
{
System.out.println("Your Choice was Windows");
}
else if (intUserInput == 2)
{
System.out.println("Your Choice was macOS");
}
else if (intUserInput == 3)
{
System.out.println("Your Choice was Linux");
}
else
{
LoopControl = false;
}
}
}
}
