The question got Duplicated once the loop starts, is there something wrong in my code?.
import java.util.Scanner;
import java.lang.Math;
public class MyClass {
public static void main(String args[]) {
Scanner lime = new Scanner(System.in);
int count = 0;
do{
System.out.println("Choose Math function to use?( A.Sine, B.Cosine, C.Tangent)");
String function= lime.nextLine();
switch(function) {
case "A": System.out.println("User choose Sine");
System.out.println("Input number: ");
System.out.println(Math.sin(Math.toRadians(lime.nextDouble())));
break;
case "B": System.out.println("User choose Cons");
System.out.println("Input number: ");
System.out.println(Math.cos(Math.toRadians(lime.nextDouble())));
break;
case "c": System.out.println("User choose Tan");
System.out.println("Input number: ");
System.out.println(Math.tan(Math.toRadians(lime.nextDouble())));
break;
}
}while (true);
}
}
Once the calculation is done, the user will be given a choice to choose another math function (this is the loop part).However there are 2 "Choose Math function to use?( A.Sine, B.Cosine, C.Tangent)". The 1st question was skip that it cannot be answer while the 2nd question is the one that could be answer. The 1st question was unnecessary. I only want the one question where the user can answer.
The Output is:
Choose Math function to use?( A.Sine, B.Cosine, C.Tangent)
A
User choose Sine
Input number:
1
0.01745240643728351
/*1st question*/ Choose Math function to use?( A.Sine, B.Cosine, C.Tangent)
/*2nd question*/ Choose Math function to use?( A.Sine, B.Cosine, C.Tangent)