3
4

More than 3 years have passed since last update.

【Java】配列から最大値・最小値を取得するプログラム例

Posted at
import java.util.*;

class Main{
public static void main(String[] args) {

    int[] data = {1,2,3,4,5,6,7,8,9,10};
    int Max = data[0];
    int Min = data[0];
    
    for(int i = 1 ; i < a.length; i++){
        if(Max < data[i]){
            Max = data[i];
            }else if(Min > data[i]{
            Min = data[i];
             }
        }
        System.out.println(Max);
    }
}
3
4
4

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
3
4