Studying (Review)/JAVA

[생활코딩] JAVA1 - 직접 컴파일 및 실행하기(3)

材硏 재연 2021. 12. 10. 10:45
728x90
반응형

입력과 출력이 있는 자바 프로그램 컴파일 및 실행하기

 

예제)

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 OkJavaGoInHome3 {

	// args : 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 + " / Floor Lamp");
		floorLamp.on();
		
		DimmingLights moodLamp = new DimmingLights(id + " moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();
		
	}

}

 

프로그램의 컴파일은 앞선 글에서 했던 방식을 그대로 하면 된다

 

하지만 실행시 그냥 java 명령어로만 실행하면

입력값이 없기 때문에 오류가 발생한다

 

입력값의 형식에 맞추어 명령어 뒤에 입력값을 넣어주면 정상적으로 실행이 가능하다

 

다른 입력값을 넣고 실행해도 정상적으로 작동한다

 

반응형