Skip to content

Instantly share code, notes, and snippets.

@sky91119
Last active May 5, 2020 18:40
Show Gist options
  • Save sky91119/ee9bdf22e2f28ef6fb6bfd5becb787d7 to your computer and use it in GitHub Desktop.
Save sky91119/ee9bdf22e2f28ef6fb6bfd5becb787d7 to your computer and use it in GitHub Desktop.
day11 과제
package array2d;
import java.util.Random;
public class test05 {
public static void main(String[] args) {
//a 가 max 값
//b 가 보드판 가로세로 배열
int[] a = new int[81];
int[][] b = new int[9][9];
//1~81까지 숫자
for(int i=0; i < a.length; i++) {
a[i] = i+1;
}
//위치에있는 두값을 봐꾸기
//Math.random() <- 무작위의 숫자 double형 을 반환해주는 메서드이다.
for(int i=0; i < 81; i++) {
int systme1 = (int)(Math.random() * 81);
int systme2 = (int)(Math.random() * 81);
int tmp = a[systme1];
a[systme1] = a[systme2];
a[systme2] = tmp;
}
//a에 있는 81 숫자를 b 로 넣기
for(int i=0, n=0; i < b.length; i++) {
for(int j=0; j < b[i].length; j++, n++) {
b[i][j] = a[n];
System.out.print((b[i][j] < 10 ? " " : "") + b[i][j] + " ");
}
System.out.println();
}
}
}
// 5x5 빙고판 만들기
//
// 1부터 25까지 랜덤하게 작성되도록 5x5 빙고판을 만들어보세요
//
// - - - - -
// 0 0 0 0 0
// 0 0 0 0 0
// 0 0 0 0 0
// 0 0 0 0 0
// 0 0 0 0 0
// (응용) 완성한 코드에서 간단한 수정으로 7x7 , 9x9 빙고판을 만들어보세요
package array2d;
public class test04 {
public static void main(String[] args) {
//상수배열로 만들기 65318724
int data[] = new int [] { 6,5,3,1,8,7,2,4 } ;
for (int i = 1; i<data.length; i++) {
for (int j=0; j < data.length; j++) {
if(data[i]<data[j]) {
int emp = data[i];
data [i] = data[j];
data[j]=emp;
}
}
}
for (int i = 0; i<data.length; i++) {
System.out.println(data[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment