Java Customクラス作成プログラムの使用


質問する



ソリューション


main.java
package pack_CustomClassBasic;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		System.out.print("숫자 입력 : ");
		double num = scanner.nextDouble();
		scanner.close();
		
		Basic basic = new Basic(num);
		double res = Basic.number();
		
		System.out.print("필드에 저장된 숫자 X 2 : " + res);
	}

}
Basic.java
package pack_CustomClassBasic;

public class Basic {
	
	static double num;
	
	public Basic(double num) {
		this.num = num;
	}
	
	public static double number() {
		double res = num * 2;
		
		return res;
	}

}

結果