플리드 avatar

다섯째 개발일지

a991102

Published: 15 Mar 2018 › Updated: 15 Mar 2018다섯째 개발일지

다섯째 개발일지

안녕하세요 #a991102 입니다.
오늘은 다섯째 개발인지인데요 오늘은 양이 짧습니다. 이해부탁드리겠습니다.

첫번재로는 배열 앞6자리 바꾸기입니다.

package 삼월십오일;

public class ArrayEx8 {
public static void main(String args[]) {

    // 45 개의 정수값을 저장하기우한 배열 생성
        int[] ball = new int [45];
        
        //배열의 각 요소에 1~45 값을 저장한다 .
        for(int i = 0; i< ball.length; i++) {
                ball[i] = i+1;
        }
        int temp = 0; //두 값을 바꾸는데 사용할 임시변슈
        int j = 0; // 임의의 값을 얻어서 저장할 변수
        
        // 배열의  i 번째 요소와 임의의 요소에 저장된 값을 서로 바꿔서 값을 섞는다.
        //0번재부터 5번째 요소까지 모두 6개만 바꾼다.
        for(int i=0; i< 6; i++){
            j = (int)(Math.random() * 45); //0부터 44범위의 정수를 얻는다
            temp  = ball[i];
            ball[i] = ball[j];
            ball[j] = temp;
            
        }
        //배열 ball 의 앞에서 부터 6개의 요소를 출력한다.
        for(int i = 0; i <6; i++){
                System.out.printf("ball[]%d=%d%n", i, ball[i]) ;
        }
        
}

}
두번째는 최대값 , 최소값 구하는 것 입니다.
package 삼월십오일;

public class ArrayEx6 {
public static void main(String args[]) {
int []score = {79,88,91,33,100,55,95};

        int max = score[0];
        int min = score[0];
        
        for(int i = 1; i < score.length; i++){
                if(score[i] > max){
                        max= score[i];
                }else if (score[i] < min ){
                        min  = score[i];
                }
        }
        System.out.println("최소값 : " + min);
        System.out.println("최대값 : " + max);
}

}

Leave 다섯째 개발일지 to:

Written by

행복한사람

Read more #kr posts


Best Posts From 플리드

We have not curated any of a991102's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From 플리드