Last active
July 13, 2017 05:25
-
-
Save alexleventer/e310c3068e284195740b985a8895c891 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class PracticeFinal | |
{ | |
public static void printMultiplicationTable(int num) | |
{ | |
// Print header | |
System.out.printf("%2s, ""); | |
for (int i = 1; i <= num; i++) | |
{ | |
System.out.printf("%2d", i); | |
} | |
System.out.println(); | |
// Print inner table | |
for (int row = 1; row <= num; row++) | |
{ | |
System.out.printf("%2d", row); | |
for (int col = 1; col <= num; col++) | |
{ | |
System.out.printf("%2d", row * col); | |
} | |
System.out.println(); | |
} | |
} | |
} |
This file contains hidden or 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
import java.util.Scanner; | |
public class Problem5A | |
{ | |
public static int[] getIntegers() | |
{ | |
Scanner keyboard = new Scanner(System.in); | |
final int TOTAL_INTEGERS = 3; | |
int[] userIntegers = new int[TOTAL_INTEGERS]; | |
for (int i = 0; i < userIntegers.length; i++) | |
{ | |
System.out.print("Enter an integer: "); | |
userIntegers[i] = keyboard.nextInt(); | |
} | |
return userIntegers; | |
} | |
public static void main(String[] args) | |
{ | |
getIntegers(); | |
} | |
} |
This file contains hidden or 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
public class SelectionSort | |
{ | |
public static void main(String[] args) | |
{ | |
Random rand = new Random(); | |
final int SIZE = 6; | |
int[] array = new int[SIZE]; | |
for (int i = 0; i < array.length; i++) | |
{ | |
array[i] = random.nextInt(200); | |
} | |
selectionSort(array); | |
} | |
public static int[] selectionSort(int[] a) | |
{ | |
int temp, min; | |
for (int i = 0; i < a.length;i++) | |
{ | |
min = i; | |
for (int j = 0; j < a.length; j++) | |
{ | |
if (a[j] < a[i]) | |
min = j; | |
} | |
if (min !+ i) | |
{ | |
temp = arr[i]; | |
arr[i] = arr[min]; | |
arr[min] = temp; | |
} | |
} | |
return a; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment