LoginSignup
0
0

More than 3 years have passed since last update.

Java SE Bronze 試験番号: 1Z0-818 (データの宣言と使用 編)(2020年10月)

Last updated at Posted at 2020-10-26

公式サイト: Java SE Bronze

oracle.PNG

目的

:cherry_blossom: Java Bronze SE 合格 :cherry_blossom:

目次

1, Java のデータ型(プリミティブ型、参照型)
2, 変数や定数の宣言と初期化、値の有効範囲
3, 配列(一次元配列)の宣言と作成、使用
4, コマンドライン引数の利用

1, Java のデータ型(プリミティブ型、参照型)

プリミティブ型

 byte
 short
 int
 long
 float
 double
 boolean
 char

参照型

 String

2, 変数や定数の宣言と初期化、値の有効範囲

変数

Variable.java
class Variable { 
    public static void main(String[] args) {

     -- Primitive type --
        byte  a = 1;
        short b = 5;
        int   c = 10;
        long  d = 100L;

        float  e = 1.0F;
        double f = 2.00;
        boolean x =  true;
        boolean y = false;
        char z = 'A';

     -- Reference type -- 
        String name = "java";
    }
}

定数  ※慣習的に大文字を使います

Constant.java
class Constant { 
    public static void main(String[] args) {

     -- Primitive type --
        final int VALUE = 10;

     -- Reference type -- 
        final String NAME = "java";
    }
}

3, 配列(一次元配列)の宣言と作成、使用

Array.java
class Array { 
    public static void main(String[] args) {

    -- int type --
    int[] numbers = {5, 10, 15, 20};

    -- String type -- 
    String[] subjects = {"Japanease", "Math", "Social", "Sience", "English"};

    for (int i = 0; i < numbers.length; i++) {
        System.out.println(numbers[i]);
    }

    for (int i = 0; i < subjects.length; i++) {
        System.out.println(subjects[i]);
    }       

    }
}

4, コマンドライン引数の利用

CommandLine
> java "クラスファイル名" "値1" "値2" ...

mainメソッドでは、Stringクラスの配列としてコマンドライン引数を受け取ります

CommandLine.java
class CommandLine { 
    public static void main(String[] args) {

        System.out.println(args[0]);
        System.out.println(args[1]);

        "よく使う命令実行文"
        "キーボードから1行の文字列の入力を受け取る"
        String s = new java.util.Scanner(System.in).nextLine();
        "キーボードから1行の整数の入力を受け取る"
        int input = new java.util.Scanner(System.in).nextInt();

        System.out.println(s);
        System.out.println(input);
    }
}

備考

アドバイスコメントなどあればぜひお願いします:blush:
適時、加執修正します❗️
1, データの宣言と使用 編
2, ループ文 編

0
0
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
0