忍者ブログ
情報処理試験など、理系の試験対策、関連知識、日記などです

Java 定数の利用

1.文法

定数は、static final  で宣言する

2.サンプル


interface Const{
  static final int  MAXVALUE = 10 ; 
  static final int MINVALUE= 1 ; 
}
class Main {
  public static void main(String[] args) {
    System.out.println(Const.MAXVALUE);
    System.out.println(Const.MINVALUE);
  }
}

3.実行結果

10
1

と表示されます。







PR

JavaScript MAP



キーと値の対応付けを管理するデータ構造です。

1.サンプル



let Users = new Map ([

  ["id1", "id1の名前"] ,

  ["id2", "id2の名前"] ,

  ["id3", "id3の名前"] ,

]);



// 要素を一つずつ表示

console.log(Users.get("id1")) ;



//要素を全部表示

for (let [key , value] of Users){

    console.log(key + "=" + value) ;

}



//要素を全部表示

Users.forEach(function(value, key){

    console.log(key + "=" + value) ;

})

2.実行結果

id1の名前

id1=id1の名前

id2=id2の名前

id3=id3の名前

id1=id1の名前

id2=id2の名前

id3=id3の名前



と表示されます。










JavaScript 配列の処理

1.サンプル

//配列の定義

let myarry = [1,2,2,3,3,3] ;

// 配列の長さ

console.log(myarry.length) ;

// 配列の出力

myarry.forEach(element => { console.log(element) ; });



2.実行結果

6
1
2
2
3
3


と表示されます