자바 무한반복 사칙연산 조건문을 수정하고 싶습니다.

익명 사용자의 이미지

아래 프로그램은 무한 한복 계산인데요.
이건 배운대로 한건데
여기서 숫자를 따로 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");
	                } } }}}
shint의 이미지

http://goorm.io

package project;
 
import java.io.*;
import java.util.StringTokenizer;
import java.util.Scanner;
 
 
//Class Scanner
//https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
 
//[JAVA] 문자열 입력과 출력 (Scanner)
//http://hyeonstorage.tistory.com/136
 
public class Main
{
    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();
            System.out.println(x);
            y = scan.nextDouble();
            System.out.println(y);
 
            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");
                }
            }
        }
    }
}

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.