JAVA에서 do~while문 예제

*** 검색어: nabiro, java, do, while, example, sample, 예제


// do~while문 예제
import java.io.*;

public class P179 {
	public static void main(String[] ar) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int a=0, b=0, c=0, total=0;
		char point=0;
		float avg=0.0f;
		
		do {
			System.out.print("a=");
			a=Integer.parseInt(in.readLine());
		} while (a < 0 || a >100);
		
		do {
			System.out.print("b=");
			b=Integer.parseInt(in.readLine());
		} while (b < 0 || b >100);
		
		do {
			System.out.print("c=");
			c=Integer.parseInt(in.readLine());
		} while (c < 0 || c >100);
		
		total = a + b + c;
		avg = total / 3.0f;
		
		switch((int)(avg / 10)) {
		case 10:
		case 9: point = 'A'; break;
		case 8: point = 'B'; break;
		case 7: point = 'C'; break;
		default : point = 'D';
		}
		
		System.out.println("Total=" + total);
		System.out.println("Avg=" + avg);
		System.out.println("Point=" + point);		
	}
}

댓글

Designed by JB FACTORY