본문 바로가기

JAVA-BAEKJOON/3단계 반복문

(12)
[백준/03-12] 10951 A+B - 4 NO.10951 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 입력데이터를 숫자로 받으며 EOF를 체크 while(sc.hasNextInt()) {// EOF인 경우 false -> 반복문 빠져나옴 int A = sc.nextInt(); int B = sc.nextInt(); System.out.println(A+B); } sc.close(); } } 📌 종료되는 조건이 없다는 것만 빼면 직전 문제랑 똑같다. 문제는 그것때문에 막혔다는거... "조건없는 input 종료"로 검색했는데 원하는 자료가 안나오다가 끝자락에 ..
[백준/03-11] 10952 A+B - 5 NO.10952 풀이코드 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; } else { System.out.println(A+B); } } sc.close(); } } 📌 지금까지와는 다르게 몇 개의 연산을 진행할지 먼저 지정하지 않는다. 몇 개의 연산이 들어올지 모르는 상황. 그럼 무한루프를 만들어 조건을 만족할때(A==0,B==0)일때 멈추는 걸로 만들면 된다. While 에 tr..
[백준/03-10] 2439 별 찍기 - 2 NO.2439 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for(int i=1; i
[백준/03-09] 2438 별 찍기 - 1 NO.2438 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); sc.close(); for(int i=0; i
[백준/03-08] 11022 A+B - 8 NO.11022 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=1; i
[백준/03-07] 11021 A+B - 7 NO.11021 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=1; i
[백준/03-06] 15552 빠른 A+B NO.15552 풀이코드 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.IOException; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter..
[백준/03-05] 25314 코딩은 체육과목 입니다 NO.25314 풀이코드 import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); if(n%4==0){ for(int i=0; i