最低価格(2562)



Java 11
  • 配列O
  • import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    
    public class Main {
    
        public static void main(String[] args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
            int[] arr = new int[9];
    
            for (int i=0; i<9; i++) {
                arr[i] = Integer.parseInt(br.readLine());
            }
    
            int max = 0;
            int index = 0;
            int count = 0;
    
            for (int value : arr) {
                count ++;
                if (value > max) {
                    max = value;
                    index = count;
                }
            }
    
            System.out.println(max);
            System.out.println(index);
        }
    }
  • 配列X
  • import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    
    public class Main {
    
        public static void main(String[] args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
            int max = 0;
            int index = 0;
    
            for (int i=0; i<9; i++) {
                int val = Integer.parseInt(br.readLine());
                if (val > max) {
                    max = val;
                    index = i+1;
                }
            }
    
            System.out.println(max);
            System.out.println(index);
        }
    }