master
Chloe Fontenot 🏳️‍⚧️ 2023-01-17 15:01:54 +07:00
parent cc8c60cd6a
commit 7fd9b8a489
1 changed files with 103 additions and 13 deletions

@ -3,15 +3,51 @@
*/
package com.calebfontenot.mp1_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class MP1_CalebFontenot {
public static void main(String[] args)
{ //2965
int[][] intArray1 = { // Horizontal
public static int[][] inputArray() {
int m, n, i, j;
// Create scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
//taking row as input
m = input.nextInt();
System.out.print("Enter the number of columns: ");
//taking column as input
n = input.nextInt();
// Declaring the two-dimensional matrix
int returnArray[][] = new int[m][n];
// Read the matrix values
System.out.println("Enter the elements of the array: ");
//loop for row
for (i = 0; i < m; i++) //inner for loop for column
{
for (j = 0; j < n; j++) {
returnArray[i][j] = input.nextInt();
}
}
//accessing array elements
System.out.println("Elements of the array are: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
return returnArray;
}
}
return null;
}
public static void main(String[] args) { //2965
int[][] horizontalTestArray = { // Horizontal
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{5, 6, 2, 1, 8, 2, 9},
@ -20,7 +56,7 @@ public class MP1_CalebFontenot {
{3, 3, 3, 3, 4, 0, 7}
};
int[][] intArray2 = { // Vertical
int[][] verticalTestArray = { // Vertical
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{5, 5, 2, 1, 8, 2, 9},
@ -28,7 +64,7 @@ public class MP1_CalebFontenot {
{1, 5, 6, 1, 4, 0, 7},
{3, 5, 3, 3, 4, 0, 7}
};
int[][] intArray3 = { // Diagonal 1
int[][] diagonalTestArray = { // Diagonal 1
{0, 1, 0, 3, 1, 6, 1},
{0, 1, 6, 8, 6, 0, 1},
{9, 6, 2, 1, 8, 2, 9},
@ -36,12 +72,66 @@ public class MP1_CalebFontenot {
{1, 3, 9, 1, 4, 0, 7},
{3, 3, 3, 9, 4, 0, 7}
};
printArray(intArray1);
System.out.println(isConsecutiveFour(intArray1));
// Create scanner
Scanner input = new Scanner(System.in);
int userInput;
do {
System.out.println("Do you want to enter an array, or use a predefined one?");
System.out.println("1. Use predefined array.");
System.out.println("2. Enter a new array.");
System.out.println("-1. quit and exit program");
System.out.print("Input: ");
userInput = input.nextInt();
if (userInput == 1) {
System.out.println("Selected \"Use predefined array\"");
System.out.println("Printing arrays...");
System.out.println("1. horizontalTestArray");
printArray(horizontalTestArray);
System.out.println("2. verticalTestArray");
printArray(verticalTestArray);
System.out.println("3. diagonalTestArray");
printArray(diagonalTestArray);
System.out.print("Input: ");
userInput = input.nextInt();
if (userInput == 1) {
if (isConsecutiveFour(horizontalTestArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
if (userInput == 2) {
if (isConsecutiveFour(verticalTestArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
if (userInput == 3) {
if (isConsecutiveFour(diagonalTestArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
userInput = 0;
}
if (userInput == 2) {
System.out.println("Selected \"Enter new array\"");
int[][] newArray = inputArray();
if (isConsecutiveFour(newArray)) {
System.out.println("Testing method returns true");
} else {
System.out.println("Testing method returns false");
}
}
} while (userInput != -1);
System.exit(0);
//printArray(intArray1);
//System.out.println(isConsecutiveFour(intArray1));
}
public static void printArray(int[][] array)
{
public static void printArray(int[][] array) {
int rowCounter = 0;
for (int x = 0; x < array.length; x++) {
for (int y = 0; y < array[x].length; y++) {
@ -54,8 +144,7 @@ public class MP1_CalebFontenot {
}
}
public static boolean isConsecutiveFour(int[][] values)
{
public static boolean isConsecutiveFour(int[][] values) {
int intCounter = 0, y = 0;
// Horizontal checking
// If the same value has been observed 4 times, return true
@ -103,7 +192,8 @@ public class MP1_CalebFontenot {
System.out.println("Checking for Diagonal matches...");
for (int rowIterate = 0; rowIterate < (values.length - 4); ++rowIterate) {
for (int x = 0; x < values.length - 1; ++x) {
if (values[x][rowIterate] == values[x][rowIterate + 1]) {}
if (values[x][rowIterate] == values[x][rowIterate + 1]) {
}
}
System.out.println("Checking next line...");