Notice
Recent Posts
Recent Comments
Today
Total
01-25 19:34
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[CH05] ๋ฐฐ์—ด ๋ณธ๋ฌธ

๐Ÿ’ป Study !/JAVA

[CH05] ๋ฐฐ์—ด

WonderJay 2022. 7. 6. 00:24
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

 

์–ธ์–ด์†Œ๊ฐœ - ์ƒํ™œ์ฝ”๋”ฉ

Java์˜ ์—ญ์‚ฌ 1995๋…„ ์ž๋ฐ”์˜ ์•„๋ฒ„์ง€๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ์ œ์ž„์Šค ๊ณ ์Šฌ๋ง๊ณผ ๊ทธ์˜ ๋™๋ฃŒ๋“ค์— ์˜ํ•ด์„œ ์‹œ์ž‘๋œ ํ”„๋กœ์ ํŠธ๋‹ค. Java๋Š” ์›๋ž˜ ๊ฐ€์ „์ œํ’ˆ์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•œ ์–ธ์–ด๋กœ ๊ณ ์•ˆ๋˜์—ˆ์ง€๋งŒ ์›น์˜ ๋“ฑ์žฅ์œผ๋กœ ์—„์ฒญ๋‚œ ์„ฑ๊ณต

opentutorials.org

http://www.yes24.com/Product/Goods/24259565

 

Java์˜ ์ •์„ - YES24

์ตœ๊ทผ 7๋…„๋™์•ˆ ์ž๋ฐ” ๋ถ„์•ผ์˜ ๋ฒ ์ŠคํŠธ ์…€๋Ÿฌ 1์œ„๋ฅผ ์ง€์ผœ์˜จ `์ž๋ฐ”์˜ ์ •์„`์˜ ์ตœ์‹ ํŒ. ์ €์ž๊ฐ€ ์นดํŽ˜์—์„œ 12๋…„๊ฐ„ ์ง์ ‘ ๋…์ž๋“ค์—๊ฒŒ ๋‹ต๋ณ€์„ ํ•ด์˜ค๋ฉด์„œ ์ดˆ๋ณด์ž๊ฐ€ ์–ด๋ ค์›Œํ•˜๋Š” ๋ถ€๋ถ„์„ ์ž˜ ํŒŒ์•…ํ•˜๊ณ  ์“ด ์ฑ…. ๋ฟ๋งŒ ์•„

www.yes24.com

 
728x90
๋ฐ˜์‘ํ˜•
LIST
Comments