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 stdIn = new Scanner(System.in);
System.out.println("세 정수의 중앙값을 구합니다");
System.out.println("a의 값 : ");
int a = stdIn.nextInt();
System.out.println("b의 값 : ");
int b = stdIn.nextInt();
System.out.println("c의 값 : ");
int c = stdIn.nextInt();
System.out.println("중앙값은"+med3(a,b,c)+"입니다");
}
}
'CS > 알고리즘' 카테고리의 다른 글
하노이의 탑 (0) | 2023.10.27 |
---|---|
시간 계산하기(손코딩) (0) | 2023.10.20 |
재귀함수와 반복문의 차이점 (0) | 2023.10.19 |
소수 구하기 (0) | 2023.10.03 |
알고리즘 스터디 문제 1,2(기수변환) (0) | 2023.09.15 |