0
0

More than 3 years have passed since last update.

Javaの標準出力を利用し配列から最大値を出力する

Last updated at Posted at 2020-08-20

某サイトのJavaの練習問題。標準入力で整数nを入力した後、n個の任意の数値を入力してその中から最大値を出力するプログラムのメモ。

import java.util.Scanner;

public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //整数nを入力
      int num = sc.nextInt();
      int max = 0;
      int[] array = new int[num];

      //n回任意の数値の入力を行う
      for(int i = 0; i < num; i++){
         array[i] = sc.nextInt();
         if(max < array[i]){
            max = array[i];
         }
      }
      System.out.println(max);
   }
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0