관리 메뉴

커리까지

자바 기초 프로그래밍 강좌 7강 - 기본 입출력(Input & Output) 본문

자바

자바 기초 프로그래밍 강좌 7강 - 기본 입출력(Input & Output)

목표는 커리 2021. 2. 9. 08:23
728x90
SMALL
public class Main {


    public static void main(String[] args){

        int coint = 0;

        for(;;){
            System.out.println('출력')
            count++;
            if(count == 10){

            }
        }
    }
}

>
출력
 .
 .
 .   

기본 입출력

  • Scanner 글래스를 이용하여 상호작용 할 수 있다.
import java.util.Scanner;
public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        System.out.print('정수를 입력하세요 : ');
        int i = sc.nextInt();
        System.out.println('입력된 정수는 '+i+'입니다.');
        sc.close();

    }
}

>
정수를 입력하세요 : 100
입력된 정수는 100입니다.    
  • 파이썬의 input()과 비슷하다.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {

    public static void main(String[] args){

        File file = new File('input.txt');
        try {
            Scanner sc = new Scanner(file);
            whilw(sc.hasNextInt()){
                System.out.println(sc.nextInt() * 100);
            }
        } catch (FileNotFoundException e){
            e.printStackTrace('파일을 읽어오는 도중에 오류가 발생하였습니다.');
        }

    }
}
  • try, catch : 실행되면 try, 안되면 catch 실행
728x90
LIST
Comments