-
https://www.acmicpc.net/problem/2562
2562번: 최댓값
9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어
www.acmicpc.net
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a[]= new int[9]; for(int i=0; i<9;i++) { a[i] = Integer.parseInt(br.readLine()); } int count=0; int max=0; for(int i=0; i<9; i++) { if(a[i]>max) { max=a[i]; count=i+1; } } System.out.println(max); System.out.println(count); } }
'백준 > 구현' 카테고리의 다른 글
15685 드래곤 커브 (0) 2024.06.28 14503 로봇 청소기 (0) 2024.06.22 1924번 2007년 (0) 2021.10.18 10817 세 수 (0) 2021.10.18 2920 음계 (0) 2021.10.18