1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package day0621;
import java.util.Scanner;
public class ScannerFor_11 {
public static void numSum()
{
//합계를 구할 숫자는? 100
//1부터 100까지의 합은 5050입니다
Scanner sc=new Scanner(System.in);
int n; //입력할 수
int sum=0;
System.out.print("합계를 구할 숫자는? ");
n=sc.nextInt();
for(int i=1;i<=n;i++)
sum+=i;
System.out.println("1부터~"+n+"까지의 합="+sum);
}
public static void factorialTest()
{
//1!=1
//2!=2
//3!=6
//10! 출력
int result=1;
for(int i=1;i<=3;i++)
{
result*=i;
System.out.println(i+"!="+result);
}
}
public static void quizFact()
{
//팩토리얼을 구할 숫자를 입력
//5!=120
Scanner sc=new Scanner(System.in);
int su, result=1;
System.out.println("팩토리얼 구할 숫자 입력");
su=sc.nextInt();
for(int i=1;i<=su;i++)
result*=i;
System.out.println(su+"!="+result);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// numSum();
// factorialTest();
// quizFact();
// class의 시작은 main method로부터 시작된다
}
}
|
cs |
----------------------------------------------------------------------------------------------------------------------------------------
numSum();
합계를 구할 숫자는? 23
1부터~23까지의 합=276
factorialTest();
1!=1
2!=2
3!=6
quizFact();
팩토리얼 구할 숫자 입력
6
6!=720
'SIST' 카테고리의 다른 글
2023.06.21 (QuizWhileTrue_13) (0) | 2023.06.30 |
---|---|
2023.06.21 (WhileTrueCount_12) (0) | 2023.06.29 |
2023.06.21 (ExForWhile_10) (0) | 2023.06.29 |
2023.06.21 (QuizFor_09) (0) | 2023.06.29 |
2023.06.21 (ForSum_08) (0) | 2023.06.29 |