アフィリエイト広告を利用しています
最新記事
カテゴリアーカイブ

広告

posted by fanblog

2019年09月04日

int型の配列3 値を変更する

配列はインデックスを使って値を取り出したり
変更したりすることができます。

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

  int[] num = {100, 200, 300};

  //インデックス2の値の取り出し
  System.out.println(num[2]);

  //インデックス1の値を変更
  num[1] = 500;

  System.out.println();
  System.out.println();

  //forで出力
  for(int i = 0; i < num.length; i++) {
   System.out.println(num[i]);
  }
  
  System.out.println();
  System.out.println();

  //拡張forで出力
  for(int j: num) {
   System.out.println(j);
  }
 }
}

===== 実行結果 =====

300


100
500
300


100
500
300

====================

地球の末路!?




検索


















×

この広告は30日以上新しい記事の更新がないブログに表示されております。