[Workshop03-문제9][Java] 정수값 세 개의 최대값, 최소값 구하기

박현아·2024년 3월 24일
0

문제

Scanner 클래스를 사용하여 키보드로 세 개의 정수값을 입력 받아서 최대값과 최소값을 구하시오. 단, if 문 사용할 것

자바 코드

Scanner sc = new Scanner(System.in);
		
System.out.println("세 정수의 최대값 구하기");
System.out.print("a 값: ");
int a = sc.nextInt();
System.out.print("b 값: ");
int b = sc.nextInt();
System.out.print("c 값: ");
int c = sc.nextInt();

int max = a;
if(b > max) {
	max = b;
} if(c > max) {
	max = c;
}

System.out.println("최대값: " + max);

출력 값

세 정수의 최대값 구하기
a 값: 5
b 값: 9
c 값: 11
최대값: 11

0개의 댓글