λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

πŸš€ Algorithm/BOJ

10952 10951

EOF (End Of File) 파일의 끝 : 데이터가 더이상 μ‘΄μž¬ν•˜μ§€ μ•Šμ„ λ•Œ

-> μž…λ ₯μ—μ„œ λ”μ΄μƒμ˜ 읽을 수 μ—†λŠ” 데이터가 μ‘΄μž¬ν•˜μ§€ μ•Šμ„ λ•Œ λ°˜λ³΅λ¬Έμ„ μ’…λ£Œν•˜λŠ” 것.

=> trueλŒ€μ‹  hasNextInt()λ₯Ό 씀

이둜 인해 hasNextInt()둜 μ •μˆ˜λ₯Ό μž…λ ₯ν•˜μ§€ μ•Šμ„ 경우, μ˜ˆμ™Έλ₯Ό λ˜μ§€λ©° μž…λ ₯ λ°›μ§€ μ•Šκ³  반볡문 μ’…λ£Œ

μž…λ ₯이 더이상 μ£Όμ–΄μ§€μ§€ μ•Šμ„ λ•Œ μ–΄λ–»κ²Œ μ²˜λ¦¬ν•΄μ•Ό ν•˜λŠ” κ°€λ₯Ό μ•Œ 수 있음.

 

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            
            if((a==0)&&(b==0)){
                break;
            }
            System.out.println((a+b));
        }
     }
 }
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(sc.hasNextInt()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}

 

'πŸš€ Algorithm > BOJ' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

8958  (0) 2021.08.18
1110  (0) 2021.08.16
2439  (0) 2021.08.15
10950  (0) 2021.08.14
2884  (0) 2021.08.14