-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayRandomShuffling
32 lines (31 loc) · 982 Bytes
/
ArrayRandomShuffling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Main {
public static void main(String[] args) {
//Listeyi random yapma
int[] myList= {5,4,8,12,9,7,0,2,4,1,6,3,12,18,24,12};
for(int i=0;i<myList.length;i++) {
int index=(int)Math.random()*myList.length;
int temp=myList[i];
myList[i]=myList[index];
myList[index]=temp;
}
for(int i=0;i<myList.length;i++) {
System.out.println(myList[i]);
}
//Çoklu Listeyi random yapma
int [][] myDimenionList= {{5,4},{8,7},{9,0}};
for(int i=0;i<myDimenionList.length;i++) {
for(int j=0;j<myDimenionList[i].length;j++) {
int i1=(int)Math.random()*myDimenionList.length;
int j1=(int)Math.random()*myDimenionList[i].length; //i yerine i1 olabilir
int temp=myDimenionList[i][j];
myDimenionList[i][j]=myDimenionList[i1][j1];
myDimenionList[i1][j1]=temp;
}
}
for(int i=0;i<myDimenionList.length;i++) {
for(int j=0;j<myDimenionList[i].length;j++) {
System.out.println(i+"-"+j+":"+myDimenionList[i][j]);
}
}
}
}