티스토리 뷰

public class ArrayShuffle {


public static void main(String[] args) {

// TODO Auto-generated method stub


int[] ori = {1,2,3,4,5,6,7,8,9};

System.out.println(java.util.Arrays.toString(ori));

int[] result = shuffle(ori);

System.out.println(java.util.Arrays.toString(result));

}


private static int[] shuffle(int[] result) {

// TODO Auto-generated method stub

int temp, seed;

for(int i=0;i<result.length;i++){

seed=(int)(Math.random()*8)+1;

temp = result[i];

result[i]=result[seed];

result[seed]=temp;

}

return result;

}

}





TAG
댓글
댓글쓰기 폼