I am making a clock and I obviously don't want the clock to pause while it's looking for inputs. i first use the switch-case statement which changes the value of timezone_str and then the local time method prints it So please tell me a way using which I can help the user exit my infinity loop (it's fine if it's not by inputting). || PLS NOTE: I USE BLUE J || Here is my code:-
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Scanner;
public class AnalogClock_Project {
public static void main(String[] args) {
int choose = 0;
boolean PutAnEndToThis = true;
String timezone_str = new String();
Scanner sc = new Scanner(System.in);
choose = sc.nextInt();
switch(choose) {
case 1:
timezone_str = "UTC";
break;
case 2:
timezone_str = "GMT";
break;
case 3:
timezone_str = "US/Central";
break;
case 4:
timezone_str = "PST";
break;
case 5:
timezone_str = "Asia/Kolkata";
break;
case 6:
timezone_str = "Japan";
break;
case 7:
timezone_str = "Europe/London";
break;
case 8:
timezone_str = "Hongkong";
break;
case 9:
timezone_str = "Australia/Sydney";
break;
case 10:
timezone_str = "Europe/Rome";
break;
case 11:
timezone_str = "US/Eastern";
break;
case 12:
timezone_str = "US/Hawaii";
break;
case 13:
timezone_str = "Africa/Cairo";
break;
case 14:
timezone_str = "America/Mexico_City";
break;
case 15:
timezone_str = "Asia/Riyadh";
break;
case 16:
timezone_str = "Europe/Moscow";
break;
case 17:
timezone_str = "Asia/Manila";
break;
}
System.out.print('\f');
Scanner sC = new Scanner(System.in);
while (PutAnEndToThis) {
LocalTime time = LocalTime.now(ZoneId.of(timezone_str));
System.out.print(time);
try{
Thread.sleep(500);
}
catch(InterruptedException ie) {}
System.out.print('\f');
}
System.out.print("\f thank you for using you clock \n hopefully you can get rich enough \n to buy a watch next time");
}
}