@@ -93,6 +93,41 @@ console.log (cartesian ([1, 2], [3, 4]));
93
93
console .log (cartesian ([1 , 2 ], []));
94
94
console .log (cartesian ([1 , 2 , 3 , 4 ], [' a' , ' b' , ' c' ]));
95
95
```
96
+ ## Java Implementation
97
+
98
+ ### [ Solution] ( ./Java/cartesianProd.java )
99
+
100
+ ``` java
101
+ /**
102
+ * @date 15/01/19
103
+ * @author SPREEHA DUTTA
104
+ */
105
+ import java.util.* ;
106
+ public class cartesianProd {
107
+ public static void prod (int n ,int arr2 [])
108
+ {
109
+ for (int i= 0 ;i< arr2. length;i++ )
110
+ System . out. println(" {" + n+ " ," + arr2[i]+ " }" );
111
+ }
112
+ public static void main (String []args )
113
+ {
114
+ Scanner sc= new Scanner (System . in);
115
+ System . out. println(" Enter size of the 2 sets" );
116
+ int m= sc. nextInt();
117
+ int n= sc. nextInt();
118
+ int arr1[]= new int [m];
119
+ int arr2[]= new int [n];
120
+ System . out. println(" Enter elements for first set" );
121
+ for (int i= 0 ;i< m;i++ )
122
+ arr1[i]= sc. nextInt();
123
+ System . out. println(" Enter elements for second set" );
124
+ for (int i= 0 ;i< n;i++ )
125
+ arr2[i]= sc. nextInt();
126
+ for (int i= 0 ;i< m;i++ )
127
+ prod(arr1[i],arr2);
128
+ }
129
+ }
130
+ ```
96
131
97
132
### C++ Implementation
98
133
@@ -210,6 +245,40 @@ function fisherYates (arr) {
210
245
fisherYates ([1 , 2 , 3 , 4 , 5 , 6 ]);
211
246
```
212
247
248
+ ## Java Implementation
249
+
250
+ ### [ Solution] ( ./Java/FisheYates.java )
251
+
252
+ ``` java
253
+ /**
254
+ * @date 15/01/19
255
+ * @author SPREEHA DUTTA
256
+ */
257
+ import java.util.* ;
258
+ public class FisheYates {
259
+ public static void main (String []args )
260
+ {
261
+ Scanner sc= new Scanner (System . in);
262
+ int n,i,rd,t;
263
+ n= sc. nextInt();
264
+ int arr[]= new int [n];
265
+ for (i= 0 ;i< n;i++ )
266
+ arr[i]= sc. nextInt();
267
+ for (i= n- 1 ;i>= 0 ;i-- )
268
+ {
269
+ Random r = new Random ();
270
+ rd= r. nextInt(n);
271
+ t= arr[rd];
272
+ arr[rd]= arr[i];
273
+ arr[i]= t;
274
+ }
275
+ System . out. print(" Shuffled array is :" );
276
+ for (i= 0 ;i< n;i++ )
277
+ System . out. print(arr[i]+ " " );
278
+ }
279
+ }
280
+ ```
281
+
213
282
### C++ Implementation
214
283
215
284
#### [ Solution ] ( ./C++/FisherYateShuffleDay19.cpp )
0 commit comments