본문 바로가기
JAVA/Algorithm

[알고리즘 Algorithm] JAVA 실습 문제 - 최댓값 구하기(1)

by haeun 하은 2022. 4. 14.
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
반응형

댓글