[11] 입력과 출력

입력과 출력

입력을 구글링 해주고 이르케 입력을 바꿔주니깐 !

우왕!

import org.opentutorials.iot.Elevator;
import org.opentutorials.iot.Lighting;
import org.opentutorials.iot.Security;

public class okayJava {

	public static void main(String[] args) {
		 Stirng id = "JAVA APT 507";
		 
		// 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("JAVA APT 507 / HALL LAMP");
		hallLamp.on();
		
		Lighting floorLamp = new Lighting("JAVA APT 507 / HALL LAMP");
		floorLamp.on();

	}

}

램프를만들어보쟝

입력을 string으로 받고싶은데 double로 바꿔야한다..
그를 위해 구글링하고 고친 코드는 아래와같다

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

	public static void main(String[] args) {
		
		String id = JOptionPane.showInputDialog("Enter a ID");
		String bright = JOptionPane.showInputDialog("Enter a Bright Level");
		 
		// 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+"/ HALL LAMP");
		floorLamp.on();
		
		DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();

	}

}

입력받는 방법

		String id = JOptionPane.showInputDialog("Enter a ID");

기억하자 !

arguments & parameter

arguments : 인자

run configurations에 들어가서..!


인자를 넣어주면

parameter : 매개변수

인자로 전달한것이 매개변수로 들어간다

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

	public static void main(String[] args) {
		
		//String id = JOptionPane.showInputDialog("Enter a ID");
		String id = args[0];
		//String bright = JOptionPane.showInputDialog("Enter a Bright Level");
		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+"/ HALL LAMP");
		floorLamp.on();
		
		DimmingLights moodLamp = new DimmingLights(id+" moodLamp");
		moodLamp.setBright(Double.parseDouble(bright));
		moodLamp.on();

	}

}


이렇게 나온다 !

이것이 제일 기초적인 방법 ..!

좋은 웹페이지 즐겨찾기