Notice
Recent Posts
Recent Comments
- Today
- Total
01-25 19:34
Tags
- Algorithm
- ํ๋ก๊ทธ๋๋จธ์ค
- BFS
- ๊ทธ๋ฆฌ๋
- ์กธ์ ์ํ
- java
- ์๋ฐ
- ์์์ ๋ ฌ
- MST
- ๊ตฌํ
- ๋ฐฑ์๋
- array
- ์ธํด
- spring
- ๋ค์ต์คํธ๋ผ
- database
- ์๋ฐ์์ ์
- OOP
- PS
- ์๋ฃ๊ตฌ์กฐ
- ๋ฌธ๋ฒ
- leetcode
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- dp
- tree
- CS
- ๋ฐฑ์ค
- Graph
- ๋ฒจ๋งํฌ๋
- pytorch
Link
Partially Committed
[CH05] ๋ฐฐ์ด ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
SMALL
EX01. ์ดํฉ๊ณผ ํ๊ท
public class source {
public static void main(String[] args){
// total sum & average
int sum = 0;
float average = 0f;
int[] score = {100, 99, 88, 56, 23};
for(int i = 0 ; i <score.length; i ++)
sum += score[i];
average = sum / (float)score.length;
System.out.println("total : " + sum);
System.out.println("average : " + average);
}
}
EX02. ์ต๋๊ฐ๊ณผ ์ต์๊ฐ
public class source {
public static void main(String[] args){
int[] score = {100, 99, 88, 56, 23};
int max = score[0]; int min = score[0];
for(int i = 1; i <score.length; i++)
{
if(score[i] > max)
max = score[i];
if(score[i] < min)
min = score[i];
}
System.out.println("max = " + max);
System.out.println("min = " + min);
}
}
EX03. Suffle
public class source {
public static void main(String[] args){
int[] numArr = {100, 99, 88, 56, 23};
for(int i = 0 ; i < 100; i++)
{
int n = (int)(Math.random() * 5);
int temp = numArr[0];
numArr[0] = numArr[n];
numArr[n] = temp;
}
for(int ele : numArr)
System.out.println(ele + " ");
}
}
EX04. ์์์ ๊ฐ์ผ๋ก ๋ฐฐ์ด ์ฑ์ฐ๊ธฐ
public class source {
public static void main(String[] args){
int [] ball = new int[45];
for(int i = 0 ; i < ball.length; i ++)
ball[i] = i+1;
int temp = 0;
int j = 0;
for(int i = 0 ; i < 6 ; i ++)
{
j = (int)(Math.random()*45);
temp = ball[i];
ball[i] = ball[j];
ball[j] = temp;
}
for(int i = 0 ; i <6 ; i++)
System.out.println(ball[i] + " ");
}
}
for(int i = 0 ; i < arr.length; i ++)
arr[i] = (int)(Math.random() * 5);
EX05. Sort
public class source {
public static void main(String[] args){
int[] arr = new int[10];
for(int i = 0 ; i <arr.length; i ++)
System.out.println(arr[i] = (int)(Math.random() * 10));
System.out.println();
for(int i = 0 ; i < arr.length -1; i ++)
{
for(int j = 0 ; j < arr.length - i - 1; j ++)
{
if(arr[j] > arr[j+1])
{
int temp = arr[j+1];
arr[j+1]= arr[j];
arr[j] = temp;
}
}
}
System.out.println();
for(int k = 0 ; k < arr.length; k ++)
System.out.println(arr[k]);
System.out.println();
}
}
EX06. ๋น๋์ ๊ตฌํ๊ธฐ
public class source {
public static void main(String[] args){
int[] arr = new int[10];
int[] cnt = new int[10];
for(int i = 0 ; i <arr.length; i ++)
{
arr[i] = (int)(Math.random() * 10);
System.out.println(arr[i]);
}
System.out.println();
for(int i = 0 ; i <arr.length; i++)
cnt[arr[i]]++;
for(int i = 0 ; i < arr.length; i ++)
System.out.println("cnt[" + i + "] = " + cnt[i]);
}
}
[EX07] ์ขํ ํ์
import java.util.Scanner;
public class source {
public static void main(String[] args){
final int SIZE = 10;
int x = 0, y = 0;
char[][] board = new char[SIZE][SIZE];
byte[][] shipBoard = {
{0,0,0,0,0,0,1,0,0},
{1,1,1,1,0,0,1,0,0},
{0,0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0},
{1,1,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0},
{0,0,0,0,0,1,1,1,0}
};
for(int i = 1 ; i < SIZE; i++) board[0][i] = board[i][0] = (char)(i+'0');
Scanner scanner = new Scanner(System.in);
while(true)
{
System.out.println("input your (x,y) : ");
String input = scanner.nextLine();
if(input.length() == 2)
{
x = input.charAt(0) - '0';
y = input.charAt(1) - '0';
if(x == 0 && y == 0) break;
}
if(input.length() != 2 || x<=0 || x>=SIZE ||y <=0 || y>=SIZE)
{
System.out.println("error!");
continue;
}
board[x][y] = shipBoard[x-1][y-1] == 1 ? 'O' : 'X';
for(int i = 0 ; i <SIZE; i ++)
System.out.println(board[i]);
System.out.println();
}
}
}
[EX08] ํ๋ ฌ์ ๊ณฑ์
public class source {
public static void main(String[] args){
int[][] m1 = {
{1, 2, 3},
{4, 5, 6}
};
int[][] m2 = {
{1, 2},
{3, 4},
{5, 6}
};
final int ROW = m1.length;
final int COL = m2[0].length;
final int M2_ROW= m2.length;
int[][] m3 = new int[ROW][COL];
for(int i = 0 ; i <ROW; i++)
for(int j = 0 ; j <COL; j++)
for(int k = 0 ; k < M2_ROW; k++)
m3[i][j] += m1[i][k] * m2[k][j];
for(int i = 0 ; i <ROW; i++){
for(int j = 0 ; j<COL; j++)
{
System.out.printf("%4d ", m3[i][j]);
}
System.out.println();
}
}
}
References
https://opentutorials.org/course/1223/4551
http://www.yes24.com/Product/Goods/24259565
728x90
๋ฐ์ํ
LIST
'๐ป Study ! > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[CH07] ๊ฐ์ฒด์งํฅํ๋ก๊ทธ๋๋ฐ3 (OOP) (0) | 2022.08.01 |
---|---|
[CH07] ๊ฐ์ฒด์งํฅํ๋ก๊ทธ๋๋ฐ2 (OOP) (0) | 2022.07.31 |
[CH06] ๊ฐ์ฒด์งํฅํ๋ก๊ทธ๋๋ฐ1 (OOP) (0) | 2022.07.07 |
[CH02.] ๋ณ์ (Variable) (0) | 2022.07.05 |
0. JAVA ๋? (0) | 2022.07.04 |
Comments