12월 27일 월요일
Chapter 1. 과제 제출
총 10개 중 10개 완료.
1-1 (Max3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package practice;
import java.util.Scanner;
public class Max3_1_1 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.println("세 정수의 최댓값을 구합니다.");
System.out.print("a의 값: "); int a = stdIn.nextInt();
System.out.print("b의 값: "); int b = stdIn.nextInt();
System.out.print("c의 값: "); int c = stdIn.nextInt();
int max = a;
if(b>max) max = b;
if(c>max) max = c;
System.out.println("최댓값은 "+max+"입니다.");
}
}
|
cs |
1-2 (Max3m)
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
|
package practice;
public class Max3m_1_2 {
static int max3(int a, int b, int c) {
int max = a;
if(b>max) max = b;
if(c>max) max = c;
return max;
}
public static void main(String[] args) {
System.out.println("max3(3,2,1) = "+max3(3,2,1));
System.out.println("max3(3,2,2) = "+max3(3,2,2));
System.out.println("max3(3,1,2) = "+max3(3,1,2));
System.out.println("max3(3,2,3) = "+max3(3,2,3));
System.out.println("max3(2,1,3) = "+max3(2,1,3));
System.out.println("max3(3,3,2) = "+max3(3,3,2));
System.out.println("max3(3,3,3) = "+max3(3,3,3));
System.out.println("max3(2,2,3) = "+max3(2,2,3));
System.out.println("max3(2,3,1) = "+max3(2,3,1));
System.out.println("max3(2,3,2) = "+max3(2,3,2));
System.out.println("max3(1,3,2) = "+max3(1,3,2));
System.out.println("max3(2,3,3) = "+max3(2,3,3));
System.out.println("max3(1,2,3) = "+max3(1,2,3));
}
}
|
cs |
1C-1 (Median)
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
|
package practice;
import java.util.Scanner;
public class Median_1C_1 {
static int med3(int a, int b, int c) {
if(a>=b)
if(b>=c)
return b;
else if(a<=c)
return a;
else
return c;
else if(a>c)
return a;
else if(b>c)
return c;
else
return b;
}
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.println("세 정수의 중앙값을 구합니다.");
System.out.print("a의 값: "); int a = stdIn.nextInt();
System.out.print("b의 값: "); int b = stdIn.nextInt();
System.out.print("c의 값: "); int c = stdIn.nextInt();
System.out.println("중앙값은 "+med3(a,b,c) +"입니다.");
}
}
|
cs |
1-3 (JudgeSign)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package practice;
import java.util.Scanner;
public class JudgeSign_1_3 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("정수를 입력하세요.: "); int n = stdIn.nextInt();
if(n>0) System.out.println("이 수는 양수입니다.");
else if(n<0) System.out.println("이 수는 음수입니다.");
else System.out.println("이 수는 0 입니다.");
}
}
|
cs |
1-4 (SumWhile)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package practice;
import java.util.Scanner;
public class SumWhile_1_4 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.println("1부터 n까지의 합을 구합니다.");
System.out.print("n의 값: "); int n = stdIn.nextInt();
int sum = 0;
int i = 1;
//사전 판단 반복 구조
while(i<=n) {
sum+=i;
i++;
}
System.out.println("1부터 "+n+"까지의 합은 "+sum+"입니다.");
}
}
|
cs |
1-5 (SumFor)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package practice;
import java.util.Scanner;
public class SumFor_1_5 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.println("1부터 n까지의 합을 구합니다.");
System.out.print("n의 값: "); int n = stdIn.nextInt();
int sum = 0;
for (int i = 1; i <= n; i++)
sum+=i;
System.out.println("1부터 "+n+"까지의 합은 "+sum+"입니다.");
}
}
|
cs |
1-6 (SumForPos)
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
|
package practice;
import java.util.Scanner;
public class SumForPos_1_6 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n;
System.out.println("1부터 n까지의 합을 구합니다.");
//0보다 큰 수를 입력해야 루프 탈출
//사후 판단 반복
do {
System.out.print("n의 값: ");
n = stdIn.nextInt();
}while(n<=0);
int sum = 0;
for (int i = 0; i <= n; i++)
sum+=i;
System.out.println("1부터 "+n+"까지의 합은 "+sum+"입니다.");
}
}
|
cs |
1C-2 (Digits)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package practice;
import java.util.Scanner;
public class Digits_1C_2 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int no;
System.out.println("2자리 정수를 입력하세요.");
do {
System.out.print("입력: ");
no = stdIn.nextInt();
}while(no<10 || no>99);
System.out.println("변수 no의 값은 "+no+"가(이) 되었습니다.");
}
}
|
cs |
1-7 (Multi99Table)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package practice;
public class Multi99Table_1_7 {
public static void main(String[] args) {
System.out.println("-----곱셈표-----");
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
//print가 아니라 printf 로 출력한 이유는 공백을 일정하게 주기 위해서.
System.out.printf("%3d",i*j);
}
System.out.println();
}
}
}
|
cs |
1-8 (TriangleLB)
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
|
package practice;
import java.util.Scanner;
public class TriangleLB_1_8 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n;
System.out.println("왼쪽 아래가 이등변 삼각형을 출력합니다.");
do {
System.out.print("몇 단 삼각형 입니까?: ");
n = stdIn.nextInt();
}while(n<=0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print("*");
System.out.println();
}
}
}
|
cs |
1 Chapter 끝!!!ㅎㅎ
'JAVA_Learn > Do it! _ Algorithm Study' 카테고리의 다른 글
#6. 2주차 과제 2[Chap03_5] (0) | 2022.01.05 |
---|---|
#5. 2주차 과제 1[Chap03_1 ~ 4] (0) | 2022.01.03 |
#4. 1주차 과제 4 [Chap02_2C-1, 14] (0) | 2021.12.30 |
#3. 1주차 과제 3 [ Chap02_ 7 ~13 ] (0) | 2021.12.29 |
#2. 1주차 과제 2 [ Chap02_ 1 ~ 6 ] (0) | 2021.12.28 |