삼각형의 밑변의 길이와 높이를 입력받아 넓이를 출력하고, "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();
}
}