-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
public class Lab3Ex02 { | ||
public static void main(String[] args) { | ||
int[][] n = new int[][] { | ||
{ 1 }, | ||
{ 1, 2, 3 }, | ||
{ 1 }, | ||
{ 1, 2, 3, 4 }, | ||
{ 1, 2 } | ||
}; | ||
|
||
for (int i = 0; i < n.length; ++i) { | ||
for (int j : n[i]) { | ||
System.out.print(j + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.Scanner; | ||
|
||
public class Lab3Ex04 { | ||
public static void main(String[] args) { | ||
System.out.print("소문자 알파벳 하나를 입력하세요."); | ||
Scanner in = new Scanner(System.in); | ||
String s = in.next(); | ||
char c = s.charAt(0); | ||
|
||
for (char i = c; i >= 'a'; --i) { | ||
for (char j = 'a'; j <= i; ++j) { | ||
System.out.print(j); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.Scanner; | ||
|
||
public class Lab3Ex06 { | ||
public static void main(String[] args) { | ||
System.out.print("금액을 입력하세요."); | ||
Scanner in = new Scanner(System.in); | ||
int price = in.nextInt(); | ||
int[] unit = { 50000, 10000, 1000, 500, 100, 50, 10, 1 }; | ||
int[] result = new int[8]; | ||
|
||
for (int i = 0; i < unit.length; ++i) { | ||
result[i] = price / unit[i]; | ||
price = price % unit[i]; | ||
if (result[i] != 0) { | ||
System.out.printf("%d원 짜리 : %d개%s", unit[i], result[i], System.lineSeparator()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
public class Lab3Ex08 { | ||
public static void main(String[] args) { | ||
System.out.print("생성할 난수의 개수 : "); | ||
Scanner in = new Scanner(System.in); | ||
int num = in.nextInt(); | ||
int[] randNum = new int[100]; | ||
for (int i = 0; i < num; ++i) { | ||
randNum[i] = (int)(Math.random() * 100); | ||
while (isOverlap(i, randNum, randNum[i])) { | ||
randNum[i] = (int)(Math.random() * 100); | ||
} | ||
} | ||
printArrayToNum(randNum, num); | ||
} | ||
|
||
public static boolean isOverlap(int index, int[] arr, int num) { | ||
for (int i = 0; i < index; ++i) { | ||
if (arr[i] == num) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void printArrayToNum(int[] randNum, int num) { | ||
for (int i = 0; i < num; ++i) { | ||
if (i % 5 == 0) { | ||
System.out.println(); | ||
} | ||
System.out.print(randNum[i] + " "); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
public class Lab3Ex10 { | ||
public static void main(String[] args) { | ||
int[][] arr = new int[4][4]; | ||
for (int i = 0; i < 10; ++i) { | ||
int randNum = (int)(Math.random() * 10); | ||
int x = 0; | ||
int y = 0; | ||
while (arr[x][y] != 0) { | ||
x = (int)((Math.random() * 10) % 4); | ||
y = (int)((Math.random() * 10) % 4); | ||
} | ||
arr[x][y] = randNum; | ||
} | ||
|
||
for (int i = 0; i < 4; ++i) { | ||
for (int j = 0; j < 4; ++j) { | ||
System.out.print(arr[i][j] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.Scanner; | ||
|
||
public class Lab3Ex12 { | ||
public static void main(String[] args) { | ||
double sum = 0.0f; | ||
for (int i = 0; i < args.length; ++i) { | ||
try { | ||
sum += Integer.valueOf(args[i]); | ||
} catch (NumberFormatException e) { | ||
sum += 0.0f; | ||
} | ||
} | ||
System.out.println("합 = " + sum); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.util.Scanner; | ||
|
||
public class Lab3Ex14 { | ||
public static void main(String[] args) { | ||
String course[] = { "Java", "C++", "HTML5", "컴퓨터구조", "네트워크" }; | ||
int score[] = {87, 88, 79, 98, 79 }; | ||
Scanner in = new Scanner(System.in); | ||
while (true) { | ||
System.out.print("과목 이름>> "); | ||
String courseName = in.next(); | ||
if (courseName.equals("그만")) { | ||
break; | ||
} else { | ||
for (int i = 0; i < course.length; ++i) { | ||
if (courseName.equals(course[i])) { | ||
System.out.printf("%s의 점수는 %d\n", course[i], score[i]); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |