Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a38c8c6

Browse files
Update Tutorial.md
1 parent eadcd1f commit a38c8c6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎ArraysAndStrings/Tutorial.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,26 @@ public void mySubString(String s,int left,int right)
106106
}
107107
```
108108

109+
**Shuffle array of integer**
110+
```
111+
public void shuffleArray(int arr[]) {
112+
Random rand = new Random();
113+
114+
//start from the last element and swap one-by-one
115+
for (int i = arr.length-1 ; i > 0 ; i--) {
116+
//find random from 0 to i
117+
int random = rand.nextInt(i);
118+
119+
//swap arr[i] with element at random index
120+
int temp = arr[random];
121+
arr[random] = arr[i];
122+
arr[i] = temp;
123+
}
124+
125+
System.out.println(Arrays.toString(arr));
126+
}
127+
```
128+
109129
**Shuffle a Deck of cards**
130+
110131
[Java Program](https://github.com/ankurjuneja/React-Java-Concepts/blob/master/src/ArraysAndStrings/Deck.java)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /