아래 프로그램은 무한 한복 계산인데요. 이건 배운대로 한건데 여기서 숫자를 따로 2번 입력 받는게 아니라 한번에 2개를 입력하고 다음에 바로 연산자를 입력해서 출력하고 싶습니다.
또 지금은 첫 번째 숫자를 정해진 숫자로 입력하면 끝나는 반복문 인데요. 이걸 코드 마지막에 계속할거냐고 질문하고 N 이라고 답하면 끝나는 프로그램으로 만들고 싶습니다. 조건문을 어디로 옮기면 이렇게 바꿀수 있을까요?
''' import java.util.Scanner;
public class nuber2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double x = 0;
double y = 0;
String z = "";
while (true) {
System.out.println("Hi, I am really good at math! Put me to the test.");
System.out.print("Please enter number and then press Enter: ");
x = scan.nextDouble();
if (x == 999) {
System.out.print("Bye bye!");
return;
} else {
System.out.print("Please enter number and then press Enter: ");
y = scan.nextDouble();
System.out.print("Please enter one of the operations +, -, * or / and press Enter:");
z = scan.next();
switch (z) {
case "+":
System.out.println( + x + " + " + y + " = " + (x + y) );
System.out.println("I'm great at subtraction!\n");
break;
case "-":
System.out.println( + x + " - " + y + " = " + (x - y) );
System.out.println("I'm great at subtraction!\n");
break;
case "*":
System.out.println( + x + " * " + y + " = " + (x * y) );
System.out.println("I'm great at subtraction!\n");
break;
case "/":
System.out.println( + x + " / " + y + " = " + (x / y) );
System.out.println("I'm great at subtraction!\n");
break;
default:
System.out.println("잘못된 연산자입니다.\n");
} } }}}
'''