I am writing a code where the user is trying to find the hypotenuse of a Triangle. My code starts by asking the user which side would they like to start with side A or side B. I used the Switch method to cover both case. what i want my code to do after either case is used, is to go back to the starting point, until the user quits. For some reason my code only does one case but doesn't go back to the beginning to start a whole new loop. Am i using the wrong method? Did I write the code improperly? What can i do to fix it?
import java.util.Scanner;
public class HandleException {
public static void main (String[] args){
int data= 0;
int data1= 0;
int sum= 0;
Scanner input = new Scanner (System.in);
//ask user for a command
System.out.println("Which side would you like to start with A or B");
String s= input.next();
char letter= s.charAt(0);
loop:while (letter!= 'q'){
switch (letter){
//if user inputs 'A'
case 'a':
System.out.println("Enter value for side A: ");
data= input.nextInt();
System.out.println("Enter next command: A : value for side A; B : Value for side B; C: Calculate; Q : Quit program.");
s=input.next();
letter=s.charAt(0);
if (letter == 'b')
System.out.println("Enter Value For side B: ");
data1= input.nextInt();
System.out.println("Enter next command: A : value for side A; B : Value for side B; C: Calculate; Q : Quit program.");
s=input.next();
letter=s.charAt(0);
if (letter== 'c')
sum=data*data+data1*data1;
int sumsrt = (int) Math.sqrt(sum);
System.out.println("The hypotenuse is: "+sumsrt);
continue;
//if user inputs 'B'
case 'b':
System.out.println("Enter value for side B: ");
data= input.nextInt();
System.out.println("Enter next command: A : value for side A; B : Value for side B; C: Calculate; Q : Quit program.");
s=input.next();
letter=s.charAt(0);
if (letter == 'a')
System.out.println("Enter Value For side a: ");
data1= input.nextInt();
System.out.println("Enter next command: A : value for side A; B : Value for side B; C: Calculate; Q : Quit program.");
s=input.next();
letter=s.charAt(0);
if (letter== 'c')
sum=data*data+data1*data1;
int sumsrt1 = (int) Math.sqrt(sum);
System.out.println("The hypotenuse is: "+sumsrt1);
continue;
}
}
}
}