main이라는 method는 JVM이 호출해서 자동으로 실행된다
main method 에서 String type의 
args 배열 이라는 매개변수를 이용해 값을 출력한다
run, configuration, arguments에서 입력가능(eclips)

System.out.println(args.length);
//args 배열의 크기를 출력

for(int i = 0; i<args.length; i++) {
System.out.println(args[i]);
//args 배열의 값을 출력

for Each문은 배열과 함께사용할때 유용하다
for(변수 : 배열변수){}
for(String str : args) {
System.out.println(str);
//배열의 각 index의 값을 

str변수로 가져와서 출력한다 

data 입력받는 방법
import java.io.*; //to use System.in
import java.utill.*; //to use Scanner

throws IOException{ //입력을 받을때 예외처리를 해주어야한다
int n = System.in.read()-'0'; //값을 읽고 int형으로 받아 ASCII값으로 반환한다
//0~9 사이의 ASCII값은 48~57이다 그래서 0을빼줄시 정수가 출력된다
System.out.println(n);

InputStreamReader id = new InputStreamReader(System.in);
//System.in 을통해 값이 입력되면 InputStreamReader라는 클래스가 생성된다

//System.in은 한단어만 받아올수있는반면

//InputStreamReader은 여러단어를 받아올수있다
while(true) {
int n = id.read(); //read method를 통해 한글자씩 읽어온다
     if(n == -1) //-1 ASCII 값은 Ctr+z를 의미한다
     break;
     System.out.println((char)n);
}

//Scanner method는 예외처리가 필요없고 간단하다
Scanner sc = new Scanner(System.in);
System.out.println(sc.next()); //next method를 이용해서 문자를 읽어온다
System.out.println(sc.nextInt()); //정수형으로 반환하는 method

'java' 카테고리의 다른 글

class, instance 변수 와 method  (0) 2019.08.02
class 객체 및 instance, 멤버요소들  (0) 2019.08.02
배열 Array  (0) 2019.08.01
보조 제어문 break, continue  (0) 2019.08.01
반복문 for, while, do while. +(제어문자)  (0) 2019.08.01

+ Recent posts