🟩 λ©”μ„œλ“œλž€?

 

νŠΉμ • μž‘μ—…μ„ μˆ˜ν–‰ν•˜λŠ” 일련의 λ¬Έμž₯듀을 ν•˜λ‚˜λ‘œ 묢은 것이닀.


 

βœ… λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜λŠ” 이유

  • 높은 μž¬μ‚¬μš©μ„± : ν•œλ²ˆ λ§Œλ“€μ–΄ 놓은 λ©”μ„œλ“œλŠ” λͺ‡ 번이고 ν˜ΈμΆœν•  수 μžˆλ‹€.
  • μ€‘λ³΅λœ μ½”λ“œμ˜ 제거 : λ°˜λ³΅λ˜λŠ” λ¬Έμž₯을 λ¬Άμ–΄μ„œ λ©”μ„œλ“œλ‘œ μž‘μ„±ν•˜λ©΄, λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λŠ” λ¬Έμž₯으둜 λŒ€μ²΄ν•  수 μžˆλ‹€.
  • ν”„λ‘œκ·Έλž¨μ˜ ꡬ쑰화 : λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•΄ mainμ—μ„œ 전체 흐름이 ν•œλˆˆμ— λ“€μ–΄μ˜€κ²Œ ꡬ쑰화 κ°€λŠ₯ν•˜λ‹€.

βœ… λ©”μ„œλ“œμ˜ μ„ μ–Έκ³Ό κ΅¬ν˜„

public static λ°˜ν™˜κ°’ν˜•μ‹ ν•¨μˆ˜λͺ…(μΈμžν˜•μ‹)//λ©”μ„œλ“œ μ„ μ–ΈλΆ€

public static int num(int a, int b){ //μ˜ˆμ‹œ
	return λ°˜ν™˜κ°’;
}

num(3,4); //λ©”μ„œλ“œ κ΅¬ν˜„λ°©λ²•

 

λ°˜ν™˜ν•˜λŠ”κ²ƒμ€ κ·Έ ν•¨μˆ˜λ₯Ό 톡해 λ¬΄μ—‡μ΄ λ‚¨λŠ”지? λ‚¨κ²¨μ§€λŠ”κ²ƒμ„ ν•œλ‹€.

 


public class Program2 {
    //둜또번호 μ €μž₯ν•˜κΈ°
    public static int[][] creatLottos(){
        int[][] lottos={{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18}};

        return lottos;
    }
    //둜또 좜λ ₯
    public static void printLottos(int[][] lottos){
        for(int i=0;i<3;i++) {
            for (int j = 0; j < 6; j++)
                System.out.printf("%4d, ",lottos[i][j]);

            System.out.println();
        }
    }
    //둜또 μ €μž₯μ†Œ λ°”κΏ”μ£ΌκΈ°
    public static void swapLottos(int[][] lottos,int i,int j){
        int[] temp = lottos[i];
        lottos[i]=lottos[j];
        lottos[j]=temp;
    }

    public static void main(String[] args) {

        int[][] lottos = creatLottos();//둜또번호 생성 ν›„ lottos에 μ €μž₯ν•΄μ£ΌκΈ°
        
        //둜또 좜λ ₯
        printLottos(lottos);

        System.out.println("\n-----------μ²«λ²ˆμ§Έμ™€ μ„Έλ²ˆμ§Έ λ°”κΎΈκΈ°-----------\n");
        
        //둜또 μ €μž₯μ†Œ λ°”κΏ”μ£ΌκΈ°
        swapLottos(lottos,0,2);//κ°’λ°”κΎΈκΈ°
        
        //둜또 좜λ ₯
        printLottos(lottos);


    }
}

 


public class BasicProgram2 {
    static int sum(int n) {
        int total = (n * (n + 1)) / 2;
        return total;
    }

    static int power(int x) {
        return ((x + 3) * (x + 3) + x / 3 * (x - 2) + 5);
    }

    public static void main(String[] args) {
        //int result = 1+2+3+4+5+6+7+8+9+10~n;
        int result = sum(11);
        System.out.printf("result : %d\n", result);

        //(x+3)*(x+3)+ x/3*(x-2)+5
        int result2 = power(7) + 3 + power(7) - power(3);
        System.out.printf("result : %d\n", result2);

        int a1 = f1();
        int a2 = f2(20, 30);
        f3(33);
        f4(9);

//        int[] lotto = new int[3];
//        print(3,5.3f,lotto);


        char[][] names = new char[3][10];

        double cnt = print(true, 4.0, names);
    }

    static double print(boolean a, double b, char[][] c) {
        return 2.2;
    }

    //print(2,3.0f,'a') ν•¨μˆ˜λ‘œ λ§Œλ“€μ–΄λ³΄μž!
//    static void print(int i, float f,int[] a){
//        System.out.printf("좜λ ₯ κ°’ : %d %.2f %c\n",i,f,a[0]);
//    }
    private static void f4(int i) {
        System.out.printf("좜λ ₯ κ°’ : %d\n", i);
    }

    private static void f3(int i) {

    }

    private static int f2(int i, int i1) {
        return 0;
    }

    private static int f1() {
        return 0;
    }
}

 

+ Recent posts