새소식

인기 검색어

비트교육_단기과정

while문 계산기

  • -

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num;
 
        float f;
 
        char calculation_opt;
        String choice = null;
        do {
 
            System.out.print("정수를 입력 : ");
 
            num = sc.nextInt();
 
            System.out.print("실수를 입력 : ");
 
            f = sc.nextFloat();
 
            System.out.print("+,-,*,/ => 연산을 입력 :  ");
 
            calculation_opt = sc.next().charAt(0);
 
            switch (calculation_opt) {
 
            case '+':
 
                System.out.println(num + f);
 
                break;
 
            case '-':
 
                System.out.println(num - f);
 
                break;
 
            case '*':
 
                System.out.println(num * f);
 
                break;
 
            case '/':
 
                System.out.println(num / f);
 
                break;
 
            default:
 
                System.out.println("연산을 잘못입력하셨습니다");
 
                break;
 
            }
            System.out.print("추가로 계산하시겠습니까? y or n : ");
            choice = sc.next();
            while (!(choice.equals("y"|| choice.equals("Y"|| choice.equals("n"|| choice.equals("N"))) {
                System.out.print("다시 입력하시오 : ");
                choice = sc.next();
            }
        } while (choice.equals("y"|| choice.equals("Y"));
 
    }
 
 
cs

 

'비트교육_단기과정' 카테고리의 다른 글

3명 성적처리 프로그램  (0) 2022.06.24
한 사람 성적처리 프로그램 : 마기창  (0) 2022.06.23
while문 구구단 출력  (0) 2022.06.23
다중 for문 별 출력  (0) 2022.06.22
지역변수 전역변수  (0) 2022.06.22
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.