1. 실행버튼 아래에 Run configuraions의 쓰임: 변수의 값을 지정할 때 사용자로부터 직접 입력받지 않아도 됩니다. configurations에 arguments에 변수의 값을 써 놓으면, 써놓은 순서대로 args 배열에 저장이 됩니다. 예를 들어, arguments에 "Pusan APT 507", "15.0" 이렇게 쓰고 Apply를 누르면 자동으로 args[0]에는 "Pusan APT 100"이, args[1]에는 "15.0"이 저장됩니다.
2. Public static void main(String[] args)할 때 이 args기 때문에 따로 선언할 필요 없습니다. 사용할 변수에 args를 넣어주면 됩니다. 예를 들어, id 변수와 bright 변수를 사용하고 싶으면, String id = args[0], String bright = args[1] 이렇게만 해주면 됩니다.
import javax.swing.JOptionPane;
import org.opentutorials.iot.DimmingLights;
import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;
public class OkJavaGoInHomeInput {
// parameter, 매개변수
public static void main(String[] args) {
String id = args[0];
String bright = args[1];
// Elevator call
Elevator myElevator = new Elevator(id);
myElevator.callForUp(1);
// Security off
Security mySecurity = new Security(id);
mySecurity.off();
// Light on
Lighting hallLamp = new Lighting(id+" / Hall Lamp");
hallLamp.on();
Lighting floorLamp = new Lighting(id+" / floorLamp");
floorLamp.on();
DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
moodLamp.setBright(Double.parseDouble(bright));
moodLamp.on();
}
}
'JAVA > 생활코딩 JAVA 입문 수업' 카테고리의 다른 글
JAVA1 - 13.2. 자바 문서 보는 법 - 패키지, 클래스, 변수, 메소드 (0) | 2023.03.29 |
---|---|
JAVA1 - 12.1. 직접 컴파일하고 실행하기 : 소개 (0) | 2023.03.28 |
JAVA1 - 11.1. 입력과 출력 (0) | 2023.03.21 |
JAVA1 - 10. 디버거 (0) | 2023.03.21 |
JAVA1 - 9.3. IOT 프로그램 만들기 (0) | 2023.03.14 |