Language_Coder 129 : 반복제어문1 - 형성평가5

boom.jun.cho·2022년 3월 15일
0

Language_Coder_JUNGOL

목록 보기
80/197

문제

삼각형의 밑변의 길이와 높이를 입력받아 넓이를 출력하고, "Continue? "에서 하나의 문자를 입력받아 그 문자가 'Y' 나 'y' 이면 작업을 반복하고 다른 문자이면 종료하는 프로그램을 작성하시오.
(넓이는 반올림하여 소수 첫째자리까지 출력한다.)​

입 출력

Base = 11
Height = 5
Triangle width = 27.5
Continue? Y
Base = 10
Height = 10
Triangle width = 50.0
Continue? N

코드

package com.jungol.algorithm080;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	
    	while(true) {
    		int base = scanner.nextInt();
    		int height = scanner.nextInt();
    		float triangleWidth = (float)base * height / 2;
    		
    		System.out.printf("Base = Height = Triangle width = %.1f\n", triangleWidth);
    		
    		System.out.print("Continue? ");
    		char exit = scanner.next().charAt(0);
    		
    		if(exit != 'Y' && exit != 'y') {
    			break;
    		}
    	}
    	
    	scanner.close();
    }
}

    		
    		
profile
하루하루 최선을

0개의 댓글