297 lines
29 KiB
HTML
297 lines
29 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>MP1_CalebFontenot.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
|
.ST0 {color: #287bde}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.ST3 {color: #9876aa}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> com.calebfontenot.mp1_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> MP1_CalebFontenot {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span>[][] <span class="ST1">inputArray</span>() {
|
|
<span class="literal">int</span> m, n, i, j;
|
|
<span class="comment">// Create scanner</span>
|
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter the number of rows: </span><span class="string">"</span>);
|
|
<span class="comment">//taking row as input </span>
|
|
m = input.nextInt();
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter the number of columns: </span><span class="string">"</span>);
|
|
<span class="comment">//taking column as input </span>
|
|
n = input.nextInt();
|
|
<span class="comment">// Declaring the two-dimensional matrix </span>
|
|
<span class="literal">int</span> returnArray[][] = <span class="literal">new</span> <span class="literal">int</span>[m][n];
|
|
<span class="comment">// Read the matrix values </span>
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Enter the elements of the array: </span><span class="string">"</span>);
|
|
<span class="comment">//loop for row </span>
|
|
<span class="literal">for</span> (i = <span class="number">0</span>; i < m; i++) <span class="comment">//inner for loop for column </span>
|
|
{
|
|
<span class="literal">for</span> (j = <span class="number">0</span>; j < n; j++) {
|
|
returnArray[i][j] = input.nextInt();
|
|
}
|
|
}
|
|
<span class="comment">//accessing array elements </span>
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Elements of the array are: </span><span class="string">"</span>);
|
|
<span class="literal">for</span> (i = <span class="number">0</span>; i < m; i++) {
|
|
<span class="literal">for</span> (j = <span class="number">0</span>; j < n; j++) {
|
|
<span class="literal">return</span> returnArray;
|
|
}
|
|
}
|
|
<span class="literal">return</span> <span class="literal">null</span>;
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">isConsecutiveFour</span>(<span class="literal">int</span>[] values) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < values.<span class="ST3">length</span> - <span class="number">4</span>; ++i) {
|
|
<span class="literal">if</span> (values[i] == values[i + <span class="number">1</span>]
|
|
&& values[i + <span class="number">1</span>] == values[i + <span class="number">2</span>]
|
|
&& values[i + <span class="number">2</span>] == values[i + <span class="number">3</span>]) {
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
} <span class="literal">else</span> {
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
}
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) { <span class="comment">//2965</span>
|
|
<span class="literal">int</span>[][] horizontalTestArray = { <span class="comment">// Horizontal</span>
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">1</span>},
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">1</span>},
|
|
{<span class="number">5</span>, <span class="number">6</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>, <span class="number">9</span>},
|
|
{<span class="number">6</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">9</span>, <span class="number">1</span>},
|
|
{<span class="number">1</span>, <span class="number">3</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>},
|
|
{<span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>}
|
|
};
|
|
|
|
<span class="literal">int</span>[][] verticalTestArray = { <span class="comment">// Vertical</span>
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">1</span>},
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">1</span>},
|
|
{<span class="number">5</span>, <span class="number">5</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>, <span class="number">9</span>},
|
|
{<span class="number">6</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">9</span>, <span class="number">1</span>},
|
|
{<span class="number">1</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>},
|
|
{<span class="number">3</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>}
|
|
};
|
|
<span class="literal">int</span>[][] diagonalTestArray1 = { <span class="comment">// Diagonal 1</span>
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">1</span>},
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">1</span>},
|
|
{<span class="number">9</span>, <span class="number">6</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>, <span class="number">9</span>},
|
|
{<span class="number">6</span>, <span class="number">9</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">9</span>, <span class="number">1</span>},
|
|
{<span class="number">1</span>, <span class="number">3</span>, <span class="number">9</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>},
|
|
{<span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">9</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>}
|
|
};
|
|
<span class="literal">int</span>[][] diagonalTestArray2 = { <span class="comment">// Diagonal 2</span>
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">1</span>},
|
|
{<span class="number">0</span>, <span class="number">1</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">1</span>},
|
|
{<span class="number">9</span>, <span class="number">6</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">2</span>, <span class="number">9</span>},
|
|
{<span class="number">6</span>, <span class="number">9</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">9</span>, <span class="number">1</span>},
|
|
{<span class="number">1</span>, <span class="number">3</span>, <span class="number">9</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>},
|
|
{<span class="number">3</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">9</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">7</span>}
|
|
};
|
|
|
|
<span class="comment">// Create scanner</span>
|
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
|
<span class="literal">int</span> userInput;
|
|
<span class="literal">do</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Do you want to enter an array, or use a predefined one?</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">1. Use predefined array.</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">2. Enter a new array.</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">-1. quit and exit program</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Input: </span><span class="string">"</span>);
|
|
userInput = input.nextInt();
|
|
<span class="literal">if</span> (userInput == <span class="number">1</span>) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Selected </span><span class="literal">\"</span><span class="string">Use predefined array</span><span class="literal">\"</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Printing arrays...</span><span class="string">"</span>);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">1. horizontalTestArray</span><span class="string">"</span>);
|
|
<span class="ST4">printArray</span>(horizontalTestArray);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">2. verticalTestArray</span><span class="string">"</span>);
|
|
<span class="ST4">printArray</span>(verticalTestArray);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">3. diagonalTestArray1</span><span class="string">"</span>);
|
|
<span class="ST4">printArray</span>(diagonalTestArray1);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">4. diagonalTestArray2</span><span class="string">"</span>);
|
|
<span class="ST4">printArray</span>(diagonalTestArray2);
|
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Input: </span><span class="string">"</span>);
|
|
userInput = input.nextInt();
|
|
<span class="literal">if</span> (userInput == <span class="number">1</span>) {
|
|
<span class="literal">if</span> (<span class="ST4">isConsecutiveFour</span>(horizontalTestArray)) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns true</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns false</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
<span class="literal">if</span> (userInput == <span class="number">2</span>) {
|
|
<span class="literal">if</span> (<span class="ST4">isConsecutiveFour</span>(verticalTestArray)) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns true</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns false</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
<span class="literal">if</span> (userInput == <span class="number">3</span>) {
|
|
<span class="literal">if</span> (<span class="ST4">isConsecutiveFour</span>(diagonalTestArray1)) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns true</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns false</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
<span class="literal">if</span> (userInput == <span class="number">4</span>) {
|
|
<span class="literal">if</span> (<span class="ST4">isConsecutiveFour</span>(diagonalTestArray2)) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns true</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns false</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
userInput = <span class="number">0</span>;
|
|
}
|
|
<span class="literal">if</span> (userInput == <span class="number">2</span>) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Selected </span><span class="literal">\"</span><span class="string">Enter new array</span><span class="literal">\"</span><span class="string">"</span>);
|
|
<span class="literal">int</span>[][] newArray = <span class="ST4">inputArray</span>();
|
|
<span class="literal">if</span> (<span class="ST4">isConsecutiveFour</span>(newArray)) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns true</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Testing method returns false</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
} <span class="literal">while</span> (userInput != -<span class="number">1</span>);
|
|
System.<span class="ST4">exit</span>(<span class="number">0</span>);
|
|
<span class="comment">//printArray(intArray1);</span>
|
|
<span class="comment">//System.out.println(isConsecutiveFour(intArray1));</span>
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printArray</span>(<span class="literal">int</span>[][] array) {
|
|
<span class="literal">int</span> rowCounter = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> x = <span class="number">0</span>; x < array.<span class="ST3">length</span>; x++) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> y = <span class="number">0</span>; y < array[x].<span class="ST3">length</span>; y++) {
|
|
System.<span class="ST2">out</span>.print(array[x][y] + <span class="string">"</span> <span class="string">"</span>);
|
|
rowCounter++;
|
|
<span class="literal">if</span> (rowCounter % (array.<span class="ST3">length</span> + <span class="number">1</span>) == <span class="number">0</span>) {
|
|
System.<span class="ST2">out</span>.println();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printArray</span>(<span class="literal">int</span>[] array) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> i : array) {
|
|
System.<span class="ST2">out</span>.print(i + <span class="string">"</span> <span class="string">"</span>);
|
|
}
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">isConsecutiveFour</span>(<span class="literal">int</span>[][] values) {
|
|
<span class="comment">// Horizontal Checking</span>
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Checking for Horizontal matches...</span><span class="string">"</span>);
|
|
<span class="literal">boolean</span> horizontalTest = <span class="ST4">horizontalMatch</span>(values);
|
|
<span class="comment">// Vertical Checking</span>
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Checking for Vertical matches...</span><span class="string">"</span>);
|
|
<span class="literal">boolean</span> verticalTest = <span class="ST4">verticalMatch</span>(values);
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Checking for Diagonal matches...</span><span class="string">"</span>);
|
|
<span class="literal">boolean</span> diagonalTest = <span class="ST4">diagonalMatch</span>(values);
|
|
<span class="literal">if</span> (horizontalTest || verticalTest || diagonalTest) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Match found!</span><span class="string">"</span>);
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
}
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">No match found.</span><span class="string">"</span>);
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">diagonalMatch</span>(<span class="literal">int</span>[][] array) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> row = <span class="number">0</span>; row < array.<span class="ST3">length</span> - <span class="number">3</span>; row++) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> col = <span class="number">0</span>; col < array[row].<span class="ST3">length</span> - <span class="number">3</span>; col++) {
|
|
<span class="comment">// Check for four consecutive numbers diagonally from top-left to bottom-right</span>
|
|
<span class="literal">if</span> (array[row][col] == array[row + <span class="number">1</span>][col + <span class="number">1</span>] && array[row + <span class="number">1</span>][col + <span class="number">1</span>] == array[row + <span class="number">2</span>][col + <span class="number">2</span>]
|
|
&& array[row + <span class="number">2</span>][col + <span class="number">2</span>] == array[row + <span class="number">3</span>][col + <span class="number">3</span>]) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Found four consecutive numbers diagonally at: </span><span class="string">"</span> + row + <span class="string">"</span><span class="string">,</span><span class="string">"</span> + col);
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
}
|
|
<span class="comment">// Check for four consecutive numbers diagonally from top-right to bottom-left</span>
|
|
<span class="literal">if</span> (array[row][col + <span class="number">3</span>] == array[row + <span class="number">1</span>][col + <span class="number">2</span>] && array[row + <span class="number">1</span>][col + <span class="number">2</span>] == array[row + <span class="number">2</span>][col + <span class="number">1</span>]
|
|
&& array[row + <span class="number">2</span>][col + <span class="number">1</span>] == array[row + <span class="number">3</span>][col]) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Found four consecutive numbers diagonally at: </span><span class="string">"</span> + row + <span class="string">"</span><span class="string">,</span><span class="string">"</span> + (col + <span class="number">3</span>));
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
}
|
|
}
|
|
}
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">verticalMatch</span>(<span class="literal">int</span>[][] values) {
|
|
<span class="literal">int</span> intCounter = <span class="number">0</span>, y = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> rowIterate = <span class="number">0</span>; rowIterate < values.<span class="ST3">length</span>; ++rowIterate) {
|
|
y = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> x = <span class="number">0</span>; x < values.<span class="ST3">length</span> - <span class="number">1</span>; ++x) {
|
|
++y;
|
|
<span class="literal">if</span> (values[x][rowIterate] == values[y][rowIterate]) {
|
|
intCounter++;
|
|
System.<span class="ST2">out</span>.println(values[x][rowIterate] + <span class="string">"</span> <span class="string">"</span> + values[y][rowIterate] + <span class="string">"</span><span class="string">, intCounter: </span><span class="string">"</span> + intCounter);
|
|
} <span class="literal">else</span> {
|
|
intCounter = <span class="number">0</span>;
|
|
System.<span class="ST2">out</span>.println(values[x][rowIterate] + <span class="string">"</span> <span class="string">"</span> + values[y][rowIterate] + <span class="string">"</span><span class="string">, intCounter: </span><span class="string">"</span> + intCounter);
|
|
}
|
|
<span class="literal">if</span> (intCounter == <span class="number">3</span>) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Vertical match!</span><span class="string">"</span>);
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
}
|
|
}
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Checking next line...</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">horizontalMatch</span>(<span class="literal">int</span>[][] values) {
|
|
<span class="literal">int</span> intCounter = <span class="number">0</span>, y = <span class="number">0</span>;
|
|
<span class="comment">// Horizontal checking</span>
|
|
<span class="comment">// If the same value has been observed 4 times, return true</span>
|
|
<span class="comment">//System.out.println("values[0].length: " + values[0].length);</span>
|
|
<span class="comment">//System.out.println("values.length: " + values.length);</span>
|
|
|
|
<span class="literal">for</span> (<span class="literal">int</span> rowIterate = <span class="number">0</span>; rowIterate < values.<span class="ST3">length</span>; ++rowIterate) {
|
|
y = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> x = <span class="number">0</span>; x < values[<span class="number">0</span>].<span class="ST3">length</span> - <span class="number">1</span>; ++x) {
|
|
++y;
|
|
<span class="literal">if</span> (values[rowIterate][x] == values[rowIterate][y]) {
|
|
intCounter++;
|
|
System.<span class="ST2">out</span>.println(values[rowIterate][x] + <span class="string">"</span> <span class="string">"</span> + values[rowIterate][y] + <span class="string">"</span><span class="string">, intCounter: </span><span class="string">"</span> + intCounter);
|
|
} <span class="literal">else</span> {
|
|
intCounter = <span class="number">0</span>;
|
|
System.<span class="ST2">out</span>.println(values[rowIterate][x] + <span class="string">"</span> <span class="string">"</span> + values[rowIterate][y] + <span class="string">"</span><span class="string">, intCounter: </span><span class="string">"</span> + intCounter);
|
|
}
|
|
<span class="literal">if</span> (intCounter == <span class="number">3</span>) {
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Horizontal match!</span><span class="string">"</span>);
|
|
<span class="literal">return</span> <span class="literal">true</span>;
|
|
}
|
|
}
|
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Checking next line...</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">return</span> <span class="literal">false</span>;
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|