728x90
320x100
package chap01;
import java.util.Scanner;
public class Median {
// 3개의 정숫값을 입력하고 중앙값을 구하여 출력
static int med3(int a, int b, int c){
if (a >= b)
if (b >= c) return b;
else if (a <= c) return a;
else return c;
else if (a > c) return a;
else if (b > c) return c;
else return b;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("세 정수의 중앙값을 구합시다.");
System.out.print("a의 값 : "); int a = scan.nextInt();
System.out.print("b의 값 : "); int b = scan.nextInt();
System.out.print("c의 값 : "); int c = scan.nextInt();
System.out.println("중앙 값은 " + med3(a, b, c) + " 입니다.");
}
}
728x90
320x100
'💻 하나씩 차곡차곡 > 자료구조 & 알고리즘(JAVA)' 카테고리의 다른 글
for문을 이용하여 1부터 n까지의 합과 그 값을 구하는 과정 출력하기 (chap01/SumVerbose1) (0) | 2022.10.09 |
---|---|
for문을 사용하여 양수만 입력받아 1부터 n까지의 합 구하기 (chap01/SumFor2) (0) | 2022.10.08 |
for문을 사용하여 정수 a, b를 포함한 그 사이의 모든 정수의 합을 구하기 (chap01/practice08) (0) | 2022.10.07 |
while문 사용하여 1부터 n까지 정수의 합 구하기 (chap01/SumWhile) (0) | 2022.10.06 |
세 값의 최댓값 구하기 (chap01/Max3) (1) | 2022.10.04 |