728x90
scanner 이용해서 a,b,c 3개의 정수를 받고 max(최댓값)을 구하기
import java.util.Scanner;
//3개의 정숫값을 입력하고 최댓값 구하기
public class class1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("세 정수의 최댓값을 구합니다");
System.out.println("a의 값 : "); int a = sc.nextInt();
System.out.println("b의 값 : "); int b = sc.nextInt();
System.out.println("c의 값 : "); int c = sc.nextInt();
int max = a; //max에 a값 넣기
if(b>max) max = b; //a보다 b가 더 크면 max는 b
if(c>max) max = c; //b보다 c가 더 크면 max는 c
System.out.println("최댓값은 "+max +" 입니다.");
}
}
728x90
반응형
'JAVA > Algorithm' 카테고리의 다른 글
[ 알고리즘 Algorithm ] 공백없는 숫자의 합 구하기 (0) | 2022.04.29 |
---|---|
[ 알고리즘 Algorithm ] 1부터 n까지 정수 합 구하기 (0) | 2022.04.29 |
[ 알고리즘 Algorithm ] 다중 for문 구구단 (0) | 2022.04.19 |
댓글