티스토리 뷰
728x90
반응형
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
|
import java.util.Scanner;
public class Q1 {
public static void main(String[] args) {
System.out.println("Hello");
Scanner sc=new Scanner (System.in);
int week=0;
int sum=0;
System.out.print("현재몸무게 : ");
int num1=sc.nextInt();
System.out.print("목표몸무게 : ");
int num2=sc.nextInt();
while (num1>num2) {
week++;
System.out.print(week+"주차감량몸무게: ");
sum=sc.nextInt();
num1-=sum;
}
System.out.println(num1+"KG 달성!! 축하합니다!!");
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q2 {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int work;
int money=5000;
float s=1.5f;
System.out.println("근무한 시간을 입력하세요 : ");
work=sc.nextInt();
if (work>8) {
System.out.println(8*money+(work-8)*5000*s+"원 입니다.");
}else {
System.out.println(work*money+"원 입니다.");
}
}
}
|
cs |
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
|
public class Q3 {
public static void main(String[] args) {
int result=0;
for (int i=1; i<101; i++) {
if (i%2==1) {
System.out.print(i + " ");
result+=i;
} else {
System.out.print("-" + i + " ");
result-=i;
}
}
System.out.println();
System.out.println("결과 : " + result);
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.util.Scanner;
public class Q4 {
public static void main(String[] args) {
int money;
Scanner sc =new Scanner(System.in);
System.out.print("총금액입력: ");
money=sc.nextInt();
System.out.println("잔돈 : "+money);
System.out.println(money/10000);
System.out.println(money%10000/5000);
System.out.println(money%10000%5000/1000);
System.out.println(money%10000%5000%1000/500);
System.out.println(money%10000%5000%1000%500/100);
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("행 개수 : ");
int hang = sc.nextInt();
for (int i=0; i<hang; i++) {
for (int j=0; j<=i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public class Q6 {
public static void main(String[] args) {
int sum =0;
int j=1;
for (int i = 77; i > 0; i--) {
sum+=i*j++;
}
System.out.println(sum);
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.util.Scanner;
public class Q7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("행 개수 : ");
int num = sc.nextInt();
for (int i = 0; i < num; i++) {
for (int j = num; j > i; j--) {
System.out.print("*");
}
System.out.println();
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import java.util.Scanner;
public class Q8 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("숫자 입력: ");
int num = sc.nextInt();
if (num%10<5) {
System.out.println("반올림 수:"+ (num-(num%10)));
}else {
System.out.println("반올림 수:"+(num+(10-(num%10))));
}
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("숫자1입력>>");
int num1 = sc.nextInt();
System.out.print("숫자2입력>>");
int num2 = sc.nextInt();
int x = 0;
int i = 0;
for (i = 1; i <= num1; ++i) {
if (num1 % i == 0 && num2 % i == 0) {
x = i;
}
}
System.out.println("최대공약수 : " + x);
int num3 = num1 * num2 / x;
System.out.println("최소공배수 : " + num3);
}
}
|
cs |
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
|
public class Q10 {
public static void main(String[] args) {
String score = "A,A,B,C,D,A,C,D,D,D,F";
String[] cut = score.split(",");
int A=0, B=0, C=0, D=0, F=0;
for (int i=0; i<cut.length; i++) {
if (cut[i].equals("A")) {
A++;
} else if (cut[i].equals("B")) {
B++;
} else if (cut[i].equals("C")) {
C++;
} else if (cut[i].equals("D")) {
D++;
} else {
F++;
}
}
System.out.println("A : " + A + "명\n"
+ "B : " + B + "명\n"
+ "C : " + C + "명\n"
+ "D : " + D + "명\n"
+ "F : " + F + "명\n");
}
}
|
cs |
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
|
public class Q11 {
public static void main(String[] args) {
int[] point = { 92, 32, 52, 9, 81, 2, 68 };
int min = Math.abs(point[0] - point[1]);
String result = null;
for (int i = 0; i < point.length; i++) {
for (int j = 1; j < point.length; j++) {
if (i != j) {
if (min > Math.abs(point[i] - point[j])) {
min = Math.abs(point[i] - point[j]);
result = "[" + point[i] + ", " + point[j] + "]";
}
}
}
}
System.out.println(result);
}
}
|
cs |
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
|
public class Q12 {
public static void main(String[] args) {
int[] point = { 56, 13, 1, 8, 87, 17, 23 };
int min = Math.abs(point[0] - point[1]);
String result = null;
for (int i = 0; i < point.length; i++) {
for (int j = 1; j < point.length; j++) {
if (i != j) {
if (min > Math.abs(point[i] - point[j])) {
min = Math.abs(point[i] - point[j]);
result = "[" + point[i] + ", " + point[j] + "]";
}
}
}
}
System.out.println(result);
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public class Q13 {
public static void main(String[] args) {
int input = 8;
for (int i=1; i<= input; i++) {
System.out.print(fibo(i) + " ");
}
}
public static int fibo(int i) {
if (i <= 1)
return i;
else
return fibo(i-2) + fibo(i-1);
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q14 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
System.out.print("1번째 수 입력 : ");
arr[0] = sc.nextInt();
System.out.print("2번째 수 입력 : ");
arr[1] = sc.nextInt();
System.out.print("3번째 수 입력 : ");
arr[2] = sc.nextInt();
System.out.print("4번째 수 입력 : ");
arr[3] = sc.nextInt();
System.out.print("5번째 수 입력 : ");
arr[4] = sc.nextInt();
int temp = 0;
int indexnum = 0;
for (int i = 0; i < arr.length; i++) {
indexnum = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[indexnum]) {
indexnum = j;
}
}
temp = arr[indexnum];
arr[indexnum] = arr[i];
arr[i] = temp;
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.util.Scanner;
public class Q15 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int n;
int sum=1;
System.out.println("n입력 :");
n=sc.nextInt();
for (int i = 1; i <=n; i++) {
System.out.print(sum+ " ");
sum += i;
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.util.Scanner;
public class Q16 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("문자열 입력 : ");
String alpa = sc.next();
String [] list = alpa.split("");
Arrays.sort(list);
for (int i = 0; i < list.length; i++) {
System.out.print(list[i]);
}
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q17 {
public static void main(String[] args) {
System.out.println(isHarshad(154));
}
public static boolean isHarshad(int num) {
int sum = 0;
int oriNum = num;
while (num > 0) {
sum += num % 10;
num = num / 10;
}
if (oriNum % sum == 0)
return true;
else
return false;
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q18 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("정수입력>>");
int num = sc.nextInt();
int array[][] = new int[num][num];
int k = 1;
for (int i = 0; i < num; i++) {
if (i % 2 == 0) {
for (int j = 0; j < num; j++) {
array[i][j] = k++;
}
} else {
for (int j = num - 1; j >= 0; j--) {
array[i][j] = k++;
}
}
}
// 출력
for (i = 0; i < num; i++) {
for (j = 0; j < num; j++) {
System.out.print(array[i][j] + "\t");
}
System.out.println();
}
}
}
|
cs |
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
|
import java.util.Scanner;
public class Q19 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("정수입력>>");
int num = sc.nextInt();
int [][] array = new int [num][num];
int sum = 1;
for (int i = 0; i <array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j]=sum;
sum ++;
}
}
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[j][i]+"\t");
}
System.out.println();
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public class Q20 {
public static String getMiddle(String str) {
String[] list = str.split("");
if (list.length % 2 == 0) {
int start = list.length / 2 - 1;
int end = list.length / 2;
return list[start]+list[end];
}
if (list.length % 2 == 1) {
int mid = list.length / 2;
return list[mid];
}
return null;
}
}
|
cs |
728x90
반응형
'스마트미디어인재개발원' 카테고리의 다른 글
스마트미디어인재개발원 자바 이론 시험 예상 문제 (0) | 2018.07.13 |
---|
댓글
"이 블로그의 모든 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday