Last active
December 12, 2015 09:29
-
-
Save casey-chow/4751816 to your computer and use it in GitHub Desktop.
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
import java.util.Scanner; | |
class ArrayStuff { | |
public static void main(String args[]) { | |
} | |
public static void tenIntegerVariables() { | |
int[] ints = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | |
for(int i : ints) { | |
System.out.println(i); | |
} | |
} | |
public static void reversingOrder() { | |
Scanner in = new Scanner(System.in); | |
int[] insts = new int[]; | |
System.out.println("Enter 10 integers."); | |
for(int i=0; i<10; i++) { | |
ints[i] = in.nextInt(); | |
} | |
for(int i=0; i>10; i++) { | |
System.out.println(ints[15 - i]); | |
} | |
} | |
public static void biggestSmallest() { | |
Scanner in = new Scanner(System.in); | |
int min = Integer.MAX_VALUE; | |
int max = Integer.MIN_VALUE; | |
int[] ints = new int[]; | |
System.out.println("Enter 15 integers."); | |
for(int i=0, i<15; i++) { | |
ints[i] = in.nextInt(); | |
} | |
for(int i=0; i<15; i++) { | |
if (ints[i] < min) { | |
min = ints[i]; | |
} | |
if (ints[i] > max) { | |
max = ints[i]; | |
} | |
} | |
System.out.print("Max: " + max); | |
System.out.print("Min: " + min); | |
} | |
public static void zerosEvenOdd() { | |
int numZeros, numEvens, numOdds; | |
int[] ints = new int[]; | |
Scanner in = new Scanner(System.in); | |
System.out.println("Enter 10 integers."); | |
for (int i=0; i<10; i++) { | |
int[i] = in.nextInt(); | |
} | |
for (i=0, i<10; i++) { | |
int theInt = int[i]; | |
if (theInt == 0) numZeros += 1; | |
if (theInt % 2 == 0) numEvens += 1; | |
else numOdds += 1; | |
} | |
} | |
public static void twoDeeArray() { | |
Scanner in = new Scanner(System.in); | |
int[][] ints = new int[][]; | |
System.out.println("Enter 25 integers."); | |
for(int i=0; i<5; i++) { | |
for(int j=0; j<5; j++) { | |
int[i][j] = in.nextInt(); | |
} | |
} | |
for(int i=0; i<5; i++) { | |
for (int j=0; j<5; j++) { | |
System.out.print(int[i][j] + "\t"); | |
} | |
System.out.print("\n"); | |
} | |
} | |
public static void matrixSum() { | |
int[][] a = new int[][]{{2, 1},{3, 5}}; | |
int[][] b = new int[][]{{-2, 3}, {4, -1}}; | |
for(int i=0; i<2; i++) { | |
for(int j=0; j<2; j++) { | |
int sum = a[i][j] + b[i][j]; | |
System.out.print(sum + "\t"); | |
} | |
System.out.print("\n"); | |
} | |
} | |
public static void matrixProduct() { | |
int[][] a = new int[][]{{2, 1},{3, 5}}; | |
int[][] b = new int[][]{{-2, 3}, {4, -1}}; | |
int[][] product; | |
for(int i=0;i<2;i++) { | |
for(int j=0; j<2; j++) { | |
for(int k=0; k<2; k++) { //running on which # in the line (be it row or column) we're on | |
//multiply the first column with the first row, etc. | |
product[i][j] += a[i][k] * b[k][j]; | |
} | |
} | |
} | |
for(int i=0; i<2; i++) { | |
for(int j=0; j<2; j++) { | |
int sum = a[i][j] + b[i][j]; | |
System.out.print(sum + "\t"); | |
} | |
System.out.print("\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment