-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseArray.java
More file actions
98 lines (80 loc) · 2.98 KB
/
UseArray.java
File metadata and controls
98 lines (80 loc) · 2.98 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
public class UseArray {
static double[] root2 = new double[100];
static double getRoot(int i){
if(root2[i] == 0){
root2[i] = Math.sqrt(i);
}
return root2[i];
}
public static void main(String args[]){
String pop = "Yesterday all my troubles seemed so far away" +
"Now it looks as though they're here to stay" +
"Oh, I believe in Yesterday" +
"Suddenly I'm not half the man I used to be";
pop = pop.toLowerCase();
int[] alpha = new int[26];
for(int a : alpha) System.out.print(a);
System.out.println();
for(int i=0; i< pop.length(); i++){
char ch = pop.charAt(i);
if(ch >= 'a' && ch <= 'z'){
alpha[ch - 'a']++;
}
}
for(int i=0; i < alpha.length; i++){
char ch = (char)(i + 'a');
System.out.println(ch + ":" + alpha[i]);
}
int[] arDays = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int month = 5;
int days = arDays[month];
System.out.println(month + " 월은 " + days + "일까지 있습니다.");
int score = 5;
String[] message = {
"",
"최고의 성적입니다. 축하합니다.",
"우수한 성적입니다.",
"보통입니다.",
"다소 부진합니다. 더 노력하세요.",
"왜 사니?"
};
int[] rank = {5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1};
System.out.println(message[rank[score]]);
double[] root1 = new double[100];
for(int i=0; i<100; i++){
root1[i] = Math.sqrt(i);
}
System.out.println("2의 제곱근 : " + root1[2]);
System.out.println("2의 제곱근 : " + getRoot(2));
System.out.println("5의 제곱근 : " + getRoot(5));
System.out.println("2의 제곱근 : " + getRoot(2));
int sum = 0;
for(int i=0; i< args.length; i++){
sum += Integer.parseInt(args[i]);
}
System.out.println("총합계 = " + sum);
int[][] scores = {
{77, 56, 70, 82},
{99, 96, 89, 88},
{81, 69, 62, 80}
};
int classSum = 0;
for(int student = 0; student < scores.length; student++){
sum = 0;
for(int subject = 0; subject < scores[0].length; subject++){
sum += scores[student][subject];
}
System.out.println( (student + 1) + "번 => 총점 : " + sum + ", 평균 : " + (float)sum/scores[0].length );
classSum += sum;
}
System.out.println();
sum=0;
for(int i=0; i<scores[0].length; i++){
sum = 0;
for(int k=0; k<scores.length; k++){
sum += scores[k][i];
}
System.out.println((i+1) + "번 과목의 총점 : " + sum + " 평균 : " + (float)sum/scores.length);
}
}
}