سلام تو این برنامه میخوام متغییز تصادفی بدون تکرار به یه ارایه دو بعدی بدم و اعداد از نوع int باشند:
package thegame;
public class TheGame {
public static void main(String[] args) {
System.out.println("Hello: ");
int a[][] = new int[3][3];
refill(a);
print(a);
}
public static
int[][] refill (int a[][]){
//int a[][]= new int[3][3];;
for(int i=0;i<3;i++){
for (int j=0;j<3;j++){
a[i][j]=(int)(Math.random()*10);
}
}
for(int i=0;i<3;i++){
for (int j=0;j<3;j++){
int w=i,e=j;
if (a[i][j]==a[i-w][j-e]){
a[i][j]=(int)(Math.random()*10);
e--;
}
w--;
}
}
return a;
}
public static void print(int a[][]){
for(int i=0;i<3;i++){
for (int j=0;j<3;j++){
System.out.print(" ["+a[i][j]+"] ");
}
System.out.println();
}
}
}
پاسخ ها