9장 - 종합문제
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
4번 - 피보나치 수열
public class Question_4
{
static int fibonachi(int n) {
if (n == 0) {
return 0;
}
else if (n == 1)
{
return 1;
}
else
{
return fibonachi(n-2) + fibonachi(n-1);
}
}
public static void main(String[] args)
{
for(int i=0; i<10; i++)
{
System.out.println(fibonachi(i));
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
5번 - 한 줄 구구단
import java.util.Scanner;
public class Question_5
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("구구단을 출력할 숫자를 입력하세요(2~9):");
int num = sc.nextInt();
for(int i=1; i<10; i++)
{
System.out.printf("%d ", i*num);
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
6번 - 입력 숫자의 총합 구하기
import java.util.Scanner;
public class Question_6
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("입력해주세여:");
String userInput = sc.nextLine();
String[] numbers = userInput.split(",");
int total =0;
for(String num : numbers)
{
num = num.trim();
int n = Integer.parseInt(num);
total = total + n;
}
System.out.printf("총합은 %d 입니다.\n", total);
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
'점프 투 자바(Java) > 23년 1월' 카테고리의 다른 글
2월 3일(금) - 9장(종합문제) (0) | 2023.02.03 |
---|---|
점프 투 자바 복습 - 3장(자료형) (0) | 2023.02.02 |
2월 1일(수) - 9장(종합문제) (0) | 2023.02.01 |
2월 1일(수) - 8장 (0) | 2023.02.01 |
1월 27일(금) - 7장 연습문제 (0) | 2023.01.27 |
댓글