🦁

2023/07/17に公開

# 配列:線形構造

(メモリアドレス)
要素(element)

それぞれの科目点数を出力！

### 1.変数１個のみ使用

OneVariable
``````
int score;   //4byte
score = 80;
System.out.println("日本語点数　：" + score );
score = 60;
System.out.println("英語点数　：" + score);
score = 100;
System.out.println("数学点数　：" + score);

//一括処理不可能、入力→処理→出力　区分不可能

``````

### 2. 変数を３個使用

ThreeVariables
``````
int jpnScore = 80;
int engScore = 60;
int mathScore = 100;

System.out.println("日本語点数　：" + jpnScore );
System.out.println("英語点数　：" + engScore);
System.out.println("数学点数　：" + mathScore);

``````

### 3. 配列を使用

Array
``````//Date Structure : データ　+　処理方法
int scores = new int[3]; // 4byte x 3 -> 12byte
s[0] = 80;
s[1] = 60;
s[2] = 100;
System.out.println("日本語点数　：" + s[0] );
System.out.println("英語点数　：" + s[1]);
System.out.println("数学点数　：" + s[2]);

//for文でも処理可能！

``````

# each-for

``````String[] seasons = {"봄","여름","가을","겨울"};
for(String data : seasons){
System.out.println(data);
}
``````
``````봄
여름
가을
겨울
``````

# MIN/MAX

Min&Max
``````
int[] num = {7,3,1,8,6..........2,4};

int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;

//MIN
for(int i = 0; i <num.length; i++) {
if(min > num[i])
min = num[i];
}

//MAX

for(int i = 0; i <num.length; i++) {
if(max < num[i])
max = num[i];
}

System.out.println("MIN:" + min);
System.out.println("MAX:" + max);

``````

# 順位、ランキング

``````
public class Array5 {

public static void main(String[] args) {

//宣言、入力
int[] score = {30,90,80,50,70};
int[] rank = {1,1,1,1,1};

//処理
for(int i=0; i<score.length; i++) {
for(int j=0; j<rank.length; j++) {
if(score[i]<score[j])
}
}

//出力
for(int i=0; i<score.length;i++) {
System.out.println(score[i] + "点は"+rank[i] + "位です。");
}

}//main() end

}//Class end

``````