Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active December 5, 2016 13:15
Show Gist options
  • Save mokomokohitsuzi/6503663d65c72cf3ea3bf5704be343f9 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/6503663d65c72cf3ea3bf5704be343f9 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習6-2
public class En06_02 {
public static void main(String[] args) {
//先頭が5なので、final変数で5を指定。
final int MAX =5;
int[] a = new int[MAX];
//for文で回しながら、結果も表示する。
//配列変数.lengthで配列の長さを取得できる。
for (int i = 0; i < a.length; i++) {
//MAXから配列のインデックス分減算する。
a[i] = MAX - i;
System.out.println("a[" + i + "] = " + a[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment