generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7.5): finish unit 7 lesson 5 activities
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package Unit7; | ||
|
||
// Have to get rid of package statement | ||
|
||
public class U7_L5_Activity_One { | ||
public static void sortAndPrintReverse(String[] arr) { | ||
for (int i = 0; i < arr.length; i++) { | ||
int high = i; | ||
for (int j = i + 1; j < arr.length; j++) { | ||
if (arr[j].compareTo(arr[high]) > 0) { | ||
high = j; | ||
} | ||
} | ||
String temp = arr[i]; | ||
arr[i] = arr[high]; | ||
arr[high] = temp; | ||
} | ||
|
||
for (int i = 0; i < arr.length; i++) { | ||
System.out.print(arr[i] + " "); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Unit7; | ||
|
||
// Have to get rid of package statement | ||
|
||
import java.util.ArrayList; | ||
|
||
public class U7_L5_Activity_Two | ||
{ | ||
|
||
public static void selectSortReverse(ArrayList<Integer> list){ | ||
|
||
for(int i=0; i<list.size(); i++){ | ||
int largestIndex=i; | ||
for(int j=i+1; j<list.size(); j++){ | ||
if(list.get(j)>list.get(largestIndex)){ | ||
largestIndex=j; | ||
} | ||
} | ||
int temp = list.get(i); | ||
|
||
list.set(i, list.get(largestIndex)); | ||
list.set(largestIndex, temp); | ||
} | ||
|
||
System.out.println(list); | ||
|
||
} | ||
|
||
} | ||
|