// リスト 7 // 実行クラス // ファイル: Calculation3.java // Calculation3クラス public class Calculation3 { // mainメソッド public static void main(String [] args) { // 変数の定義 int a = 5; int b = 10; int c = 15; int result1; double f = 1.23; double g = 6.78; double result2; // コマンドライン引数の処理 if (args.length != 2) { // (1)引数のString配列の要素数が2つではないときの処理 System.out.println("2つの引数を入力してください(デフォルト値は5, 10です)."); } else { // コマンドライン引数が入力されたときの処理 // (2)文字列をint型に変換 a = Integer.parseInt(args[0]); b = Integer.parseInt(args[1]); } // (1)コンストラクタの呼び出しによるオブジェクトの生成 Addition3 addition3 = new Addition3(); // メソッドの呼び出し result1 = addition3.addParameter(); System.out.println("足し算メソッド(1)(値はコンストラクタで設定): result = " + result1); result1 = addition3.addParameter(a, b); System.out.println("足し算メソッド(1)(値はコマンドライン引数で設定): result = " + result1); } // mainメソッド } // Calculation3クラス