0
1

More than 3 years have passed since last update.

java(配列)

Last updated at Posted at 2020-05-08

配列作業手順

int[] scores;           //①
scores = new int[5];    //②

[5] = 0,1,2,3,4 中身ゼロから数えて[5]

①と②同時に行う

int[] scores = new int[5];    //①②

配列作成省略記法

int[] scores1 = new int[] {10, 20, 30, 40, 50};   
int[] scores2 = {10, 20, 30, 40, 50};   

上下同じ意味

forループで配列を回す

int[] scores = {10, 20, 30, 40, 50}; 
for (int i = 0; i < scores.length; i++) {
  System.out.println(scores[i]);

ループ変数名は任意で指定可能

拡張 for 文で配列を回す

int[] scores = {10, 20, 30, 40, 50}; 
for (int value : scores) {
  System.out.println(value);

上のfor文であったループ変数や配列の添字を記述する必要がなくなる

length使用方法

配列のlength
文字列のlength()

0
1
0

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
1