![[java] 백준 2581번 소수](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcAgs5p%2Fbtranby24vF%2FPiO2lD3xMgzrDp1cEvrTD0%2Fimg.jpg)
문제 조건 1. M이상 N이하의 자연수 중 소수인 것을 모두 찾아 첫째 줄에 합 2. 둘째 줄에 1번 조건의 소수 중 최솟값 출력 3. M이상 N이하의 자연수 중 소수가 없을 경우 첫째 줄에 -1 출력 import java.util.Scanner; // 2581 class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int M = sc.nextInt(); int N = sc.nextInt(); int[] arr = new int[N]; int count, tot=0, sosuCount=0; for(int i=M; i
![[java] 백준 11653번 소인수분해](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FBFcJJ%2Fbtrai8AZEbF%2FJhygwPEw9Ao9jEabx9sXAk%2Fimg.jpg)
문제 조건 1. 소인수 분해 결과를 한 줄에 하나씩 오름차순으로 출력 (1,2,3 ~~) 2. N이 1인 경우 아무것도 출력 안함 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if(N == 1) { sc.close(); } for(int i=2; i
![[java] 백준 4153번 직각삼각형](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbfBVlE%2FbtracZEQNDQ%2FylLWjeZ1C8qyWnw9fIxmxK%2Fimg.jpg)
마지막에 0 0 0 을 입력시켰을 때 반복문을 종료 시켜주면 되겠다 싶어 이런식으로 구현을 했고 Math.pow 함수를 쓰면 ex) Math.pow(3,2) => 3의 제곱인 9가 나오는 것이다. 그래서 아래와 같이 코드를 작성했다. 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(); int c = sc.nextInt(); // 입력이 0 0 0 일때 반복문 탈출 if(a == 0 && b == 0 && c == 0){ break; } ..
![[java] 백준 1978번 소수 찾기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fmvc7h%2FbtrackPD0yb%2F7syIRfPsPaltILariYsHH1%2Fimg.jpg)
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int sosu=0; for(int i=0; i