728x90
반응형
SMALL
자가진단1 : 587
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i = 0;
solution(n, i);
}
public static void solution(int n, int i){
if(i == n) return;
System.out.println("recursive");
i++;
solution(n, i);
}
}
자가진단2: 588
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i = n;
solution(i);
}
public static void solution(int i){
if(i == 0) return;
System.out.print(i + " ");
i--;
solution(i);
}
}
자가진단3: 589
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int answer = solution(n);
System.out.println(answer);
}
public static int solution(int n){
if(n==1) return 1;
else if(n>1) return solution(n-1) + solution(n-2);
else return 0;
}
}
자가진단4: 592
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int answer = solution(n);
System.out.println(answer);
}
public static int solution(int n){
if(n > 0) return (int)Math.pow(n%10,2) + solution(n/10);
else return 0;
}
}
자가진단5 : 590
import java.util.Scanner;
public class Main {
public static int N;
public static int[] arr = new int[11];
static void dice(int n){
if(n > N) {
for(int i=1; i<=N; i++) System.out.print(arr[i] + " ");
System.out.println();
return ;
}
for(int i = arr[n-1]; i<=6; i++){
arr[n] = i;
dice(n+1);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
arr[0] =1;
dice(1);
}
}
자가진단6 : 591
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(solution(n));
}
public static int solution(int n){
if(n == 1) return 1;
else return solution(n/2) + solution(n-1);
}
}
728x90
반응형
LIST
'프로그래밍 > 자바' 카테고리의 다른 글
[자바] 정올 593 ~ 601 : 문자열1 - 자가진단1~9 (1) | 2023.10.04 |
---|---|
[자바] 정올 231 ~ 236 : 함수3 - 형성평가1~6 (0) | 2023.10.03 |
[자바] 정올 175 ~ 181 : 함수2 - 형성평가1~7 (0) | 2023.10.03 |
[자바] 정올 579 ~ 586 : 함수2 - 자가진단1~8 (0) | 2023.10.03 |
[자바] 정올 170 ~ 174 : 함수1 - 형성평가1 ~ 5 (0) | 2023.10.02 |