Algorithm/SWEA
[Java] SWEA2068 - 최대수 구하기
th42500
2021. 12. 17. 18:00
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
💡 포인트
1️⃣ 테스트케이스 T만큰 반복해서 답 출력
2️⃣ 10개의 수를 입력 받아서 각 수 비교
3️⃣ 테스트케이스는 1부터 시작
1️⃣ 부등호를 이용한 대소 비교
✔ 소스코드
import java.util.Scanner;
public class Solution {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int i=0;i<T;i++){
int[] num = new int[10];
int result = 0;
for(int j=0;j<num.length;j++) {
num[j] = sc.nextInt();
if(result <= num[j]){
result = num[j];
}
}
System.out.println("#" + (i+1) + " " + result);
}
}
}
2️⃣ Math.max()를 이용한 대소 비교
✔ 소스코드
import java.util.Scanner;
public class Solution { // 2068. 최대수 구하기
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int t = 1; t <= T; t++) {
int max = -1;
for (int i = 0; i < 10; i++) {
int num = sc.nextInt();
max = Math.max(max, num);
}
System.out.println("#" + t + " " + max);
}
}
}