I'm knew with multi-dimensional arrays and I kind of know the basics but I'm stuck on combining them into a boolean method. In this case, I'm trying to find out how I can make this method simplified which will function as:
Comparing one array with a location (row:column) to another array (with the same location).
If all locations from both arrays match, it should return true.
The method below works with what I have for my code but I want to know the proper way on how to not "hard code" the numbers single handedly. Would I need to use a nested for loop for comparing both arrays?
Thanks for the assistance~
public static boolean gameIsWon(int[][] workingPuzzle, int[][] solvedPuzzle)
{
if (workingPuzzle[0][0] == solvedPuzzle[0][0] &&
workingPuzzle[0][1] == solvedPuzzle[0][1] &&
workingPuzzle[0][2] == solvedPuzzle[0][2] &&
workingPuzzle[0][3] == solvedPuzzle[0][3] &&
workingPuzzle[0][4] == solvedPuzzle[0][4] &&
workingPuzzle[0][5] == solvedPuzzle[0][5] &&
workingPuzzle[0][6] == solvedPuzzle[0][6] &&
workingPuzzle[0][7] == solvedPuzzle[0][7] &&
workingPuzzle[0][8] == solvedPuzzle[0][8] &&
workingPuzzle[1][0] == solvedPuzzle[1][0] &&
workingPuzzle[1][1] == solvedPuzzle[1][1] &&
workingPuzzle[1][2] == solvedPuzzle[1][2] &&
workingPuzzle[1][3] == solvedPuzzle[1][3] &&
workingPuzzle[1][4] == solvedPuzzle[1][4] &&
workingPuzzle[1][5] == solvedPuzzle[1][5] &&
workingPuzzle[1][6] == solvedPuzzle[1][6] &&
workingPuzzle[1][7] == solvedPuzzle[1][7] &&
workingPuzzle[1][8] == solvedPuzzle[1][8] &&
workingPuzzle[2][0] == solvedPuzzle[2][0] &&
workingPuzzle[2][1] == solvedPuzzle[2][1] &&
workingPuzzle[2][2] == solvedPuzzle[2][2] &&
workingPuzzle[2][3] == solvedPuzzle[2][3] &&
workingPuzzle[2][4] == solvedPuzzle[2][4] &&
workingPuzzle[2][5] == solvedPuzzle[2][5] &&
workingPuzzle[2][6] == solvedPuzzle[2][6] &&
workingPuzzle[2][7] == solvedPuzzle[2][7] &&
workingPuzzle[2][8] == solvedPuzzle[2][8] &&
workingPuzzle[3][0] == solvedPuzzle[3][0] &&
workingPuzzle[3][1] == solvedPuzzle[3][1] &&
workingPuzzle[3][2] == solvedPuzzle[3][2] &&
workingPuzzle[3][3] == solvedPuzzle[3][3] &&
workingPuzzle[3][4] == solvedPuzzle[3][4] &&
workingPuzzle[3][5] == solvedPuzzle[3][5] &&
workingPuzzle[3][6] == solvedPuzzle[3][6] &&
workingPuzzle[3][7] == solvedPuzzle[3][7] &&
workingPuzzle[3][8] == solvedPuzzle[3][8] &&
workingPuzzle[4][0] == solvedPuzzle[4][0] &&
workingPuzzle[4][1] == solvedPuzzle[4][1] &&
workingPuzzle[4][2] == solvedPuzzle[4][2] &&
workingPuzzle[4][3] == solvedPuzzle[4][3] &&
workingPuzzle[4][4] == solvedPuzzle[4][4] &&
workingPuzzle[4][5] == solvedPuzzle[4][5] &&
workingPuzzle[4][6] == solvedPuzzle[4][6] &&
workingPuzzle[4][7] == solvedPuzzle[4][7] &&
workingPuzzle[4][8] == solvedPuzzle[4][8] &&
workingPuzzle[5][0] == solvedPuzzle[5][0] &&
workingPuzzle[5][1] == solvedPuzzle[5][1] &&
workingPuzzle[5][2] == solvedPuzzle[5][2] &&
workingPuzzle[5][3] == solvedPuzzle[5][3] &&
workingPuzzle[5][4] == solvedPuzzle[5][4] &&
workingPuzzle[5][5] == solvedPuzzle[5][5] &&
workingPuzzle[5][6] == solvedPuzzle[5][6] &&
workingPuzzle[5][7] == solvedPuzzle[5][7] &&
workingPuzzle[5][8] == solvedPuzzle[5][8] &&
workingPuzzle[6][0] == solvedPuzzle[6][0] &&
workingPuzzle[6][1] == solvedPuzzle[6][1] &&
workingPuzzle[6][2] == solvedPuzzle[6][2] &&
workingPuzzle[6][3] == solvedPuzzle[6][3] &&
workingPuzzle[6][4] == solvedPuzzle[6][4] &&
workingPuzzle[6][5] == solvedPuzzle[6][5] &&
workingPuzzle[6][6] == solvedPuzzle[6][6] &&
workingPuzzle[6][7] == solvedPuzzle[6][7] &&
workingPuzzle[6][8] == solvedPuzzle[6][8] &&
workingPuzzle[7][0] == solvedPuzzle[7][0] &&
workingPuzzle[7][1] == solvedPuzzle[7][1] &&
workingPuzzle[7][2] == solvedPuzzle[7][2] &&
workingPuzzle[7][3] == solvedPuzzle[7][3] &&
workingPuzzle[7][4] == solvedPuzzle[7][4] &&
workingPuzzle[7][5] == solvedPuzzle[7][5] &&
workingPuzzle[7][6] == solvedPuzzle[7][6] &&
workingPuzzle[7][7] == solvedPuzzle[7][7] &&
workingPuzzle[7][8] == solvedPuzzle[7][8] &&
workingPuzzle[8][0] == solvedPuzzle[8][0] &&
workingPuzzle[8][1] == solvedPuzzle[8][1] &&
workingPuzzle[8][2] == solvedPuzzle[8][2] &&
workingPuzzle[8][3] == solvedPuzzle[8][3] &&
workingPuzzle[8][4] == solvedPuzzle[8][4] &&
workingPuzzle[8][5] == solvedPuzzle[8][5] &&
workingPuzzle[8][6] == solvedPuzzle[8][6] &&
workingPuzzle[8][7] == solvedPuzzle[8][7] &&
workingPuzzle[8][8] == solvedPuzzle[8][8]
)
return true;
else
return false;
}
You need to learn about loops.
And about storing a two-dimensional matrix in a one-dimensional array using index mapping (which is easier to handle than a two-dimensional array).
But in this particular case:
return java.util.Arrays.deepEquals(workingPuzzle, solvedPuzzle);
Use nested for loops based on the array lengths.
public static boolean gameIsWon(int[][] workingPuzzle, int[][] solvedPuzzle) {
if(workingPuzzle.length != solvedPuzzle.length) {
return false;
}
for(int i = 0; i < workingPuzzle.length; i++) {
if(workingPuzzle[i].length != solvedPuzzle[i].length) {
return false;
}
for(int j = 0; j < workingPuzzle[i].length; j++) {
if(workingPuzzle[i][j] != solvedPuzzle[i][j]) {
return false;
}
}
}
return true;
}
Related
I have a program that quotes up to 57 customizable products at one time. If there is a compatibility issue within one of the products the customer designs, an error pops up and a quote is not generated. I have it so if the generate button on line 57 is clicked, the program will check if lines 57, 56, 55... down to 1 are correct, then it will generate if they are. If line 56 is clicked, it checks 56 down to 1.
Is there a ways to loop is so that I only have to write it out once?
Here is my code:
if(e.getSource() == CA1.BTNgeneratequoteCA1)
{
if(CA1.generateCA1 == true)
{
try
{
FillAllKIS();
E2fill();
FillQuote();
}
catch(IOException y)
{
Logger.severe(y.getMessage());
}
RecordAllLines();
}
}
// if statments for lines 2 to 56 here
if(e.getSource() == CA57.BTNgeneratequoteCA1)
{
if(CA1.generateCA1 == true && CA2.generateCA1 == true && CA3.generateCA1 == true && CA4.generateCA1 == true && CA5.generateCA1 == true &&
CA6.generateCA1 == true && CA7.generateCA1 == true && CA8.generateCA1 == true && CA9.generateCA1 == true && CA10.generateCA1 == true &&
CA11.generateCA1 == true && CA12.generateCA1 == true && CA13.generateCA1 == true && CA14.generateCA1 == true && CA15.generateCA1 == true &&
CA16.generateCA1 == true && CA17.generateCA1 == true && CA18.generateCA1 == true && CA19.generateCA1 == true && CA20.generateCA1 == true &&
CA21.generateCA1 == true && CA22.generateCA1 == true && CA23.generateCA1 == true && CA24.generateCA1 == true && CA25.generateCA1 == true &&
CA26.generateCA1 == true && CA27.generateCA1 == true && CA28.generateCA1 == true && CA29.generateCA1 == true && CA30.generateCA1 == true &&
CA31.generateCA1 == true && CA32.generateCA1 == true && CA33.generateCA1 == true && CA34.generateCA1 == true && CA35.generateCA1 == true &&
CA36.generateCA1 == true && CA37.generateCA1 == true && CA38.generateCA1 == true && CA39.generateCA1 == true && CA40.generateCA1 == true &&
CA41.generateCA1 == true && CA42.generateCA1 == true && CA43.generateCA1 == true && CA44.generateCA1 == true && CA45.generateCA1 == true &&
CA46.generateCA1 == true && CA47.generateCA1 == true && CA48.generateCA1 == true && CA49.generateCA1 == true && CA50.generateCA1 == true &&
CA51.generateCA1 == true && CA52.generateCA1 == true && CA53.generateCA1 == true && CA54.generateCA1 == true && CA55.generateCA1 == true &&
CA56.generateCA1 == true && CA57.generateCA1 == true)
{
try
{
FillAllKIS();
E2fill();
FillQuote();
}
catch(IOException y)
{
Logger.severe(y.getMessage());
}
RecordAllLines();
}
I thought about doing it with a list filled with the instances of the classes but I'm struggling to think of how the logic would work for checking the boolean of each line, since there is another one to check with each added line item.
/* Create a list to hold CA1..CA57 */
List<MyClass> allCas = new ArrayList<>();
/* As you create CA1..CA57, whether in a loop or hardcoded, add them to your list, in order*/
...
allCas.add(CA1);
...
allCas.add(CA31);
...
allCas.add(CA57);
/* When button is clicked, find the related CA instance and check the preceding objects too. */
int selected = IntStream.range(0, allCas.size())
.filter(idx -> e.getSource() == allCas.get(idx))
.findFirst().getAsInt() + 1;
if (allCas.stream().limit(selected).allMatch(ca -> ca.generateCA1)) {
/* Fill quote and stuff. */
...
}
I'm making a checkwinner class that checks 4 arrays for a bingo win, and it is wayyyy too long. Any way i can shorten it? I know you can use a for loop, but I have no idea how.thank you in advance!
public static boolean checkWinner(String[][] card, String[][] card2, String[][] card3, String[][]card4) {
if ((card[0][0] == card[0][1] && card[0][1] == card[0][2] && card[0][2] == card[0][3] && card[0][3] == card[0][4]) || (card[1][0] == card[1][1] && card[1][1] == card[1][2] && card[1][2] == card[1][3] && card[1][3] == card[1][4])|| (card[2][0] == card[2][1] && card[2][1] == card[2][3] && card[2][3] == card[2][4]) || (card[3][0] == card[3][1] && card[3][1] == card[3][2] && card[3][2] == card[3][3] && card[3][3] == card[3][4])
|| (card[4][0] == card[4][1] && card[4][1] == card[4][2] && card[4][2] == card[4][3] && card[4][3] == card[4][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card[0][0] == card[1][0] && card[1][0] == card[2][0] && card[2][0] == card[3][0] && card[3][0] == card[4][0]) || (card[0][1] == card[1][1] && card[1][1] == card[2][1] && card[2][1] == card[3][1] && card[3][1] == card[4][1])
|| (card[0][2] == card[1][2] && card[1][2] == card[3][2] && card[3][2] == card[4][2]) || (card[0][3] == card[1][3] && card[1][3] == card[2][3] && card[2][3] == card[3][3] && card[3][3] == card[4][3])
|| (card[0][4] == card[1][4] && card[1][4] == card[2][4] && card[2][4] == card[3][4] && card[3][4] == card[4][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card[0][0] == card[1][1] && card[1][1] == card[3][3] && card[3][3]== card[4][4]) || (card[4][0] == card[3][1] && card[3][1] == card[1][3] && card[1][3]== card[0][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card2[0][0] == card2[0][1] && card2[0][1] == card2[0][2] && card2[0][2] == card2[0][3] && card2[0][3] == card2[0][4]) || (card2[1][0] == card2[1][1] && card2[1][1] == card2[1][2] && card2[1][2] == card2[1][3] && card2[1][3] == card2[1][4])
|| (card2[2][0] == card2[2][1] && card2[2][1] == card2[2][3] && card2[2][3] == card2[2][4]) || (card2[3][0] == card2[3][1] && card2[3][1] == card2[3][2] && card2[3][2] == card2[3][3] && card2[3][3] == card2[3][4])
|| (card2[4][0] == card2[4][1] && card2[4][1] == card2[4][2] && card2[4][2] == card2[4][3] && card2[4][3] == card2[4][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card2[0][0] == card2[1][0] && card2[1][0] == card2[2][0] && card2[2][0] == card2[3][0] && card2[3][0] == card2[4][0]) || (card2[0][1] == card2[1][1] && card2[1][1] == card2[2][1] && card2[2][1] == card2[3][1] && card2[3][1] == card2[4][1])
|| (card2[0][2] == card2[1][2] && card2[1][2] == card2[3][2] && card2[3][2] == card2[4][2]) || (card2[0][3] == card2[1][3] && card2[1][3] == card2[2][3] && card2[2][3] == card2[3][3] && card2[3][3] == card2[4][3])
|| (card2[0][4] == card2[1][4] && card2[1][4] == card2[2][4] && card2[2][4] == card2[3][4] && card2[3][4] == card2[4][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card2[0][0] == card2[1][1] && card2[1][1] == card2[3][3] && card2[3][3]== card2[4][4]) || (card2[4][0] == card2[3][1] && card2[3][1] == card2[1][3] && card2[1][3]== card2[0][4])) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
} else if ((card3[0][0] == card3[0][1] && card3[0][1] == card3[0][2] && card3[0][2] == card3[0][3] && card3[0][3] == card3[0][4]) || (card3[1][0] == card3[1][1] && card3[1][1] == card3[1][2] && card3[1][2] == card3[1][3] && card3[1][3] == card3[1][4])|| (card3[2][0] == card3[2][1] && card3[2][1] == card3[2][3] && card3[2][3] == card3[2][4])
|| (card3[3][0] == card3[3][1] && card3[3][1] == card3[3][2] && card3[3][2] == card3[3][3] && card3[3][3] == card3[3][4])
|| (card3[4][0] == card3[4][1] && card3[4][1] == card3[4][2] && card3[4][2] == card3[4][3] && card3[4][3] == card3[4][4])) {
System.out.println("CPU CALLS BINGO! YOU LOSE!");
displayBoard(card, card2, card3, card4);
System.exit(0);
return false;
}
}
return true;
}
I think what you have written in the checkWinner method is quite short, because using loops will give make your code more tedious to work with and it will be a lot longer. But, I have written down the CheckWinner method using loops. I haven't ran this code in IDE. So, there maybe some bugs. I hope is helped you.
NOTE:below code is only implementing for the card method only
public static boolean checkWinner(String[][] card, String[][] card2, String[][] card3, String[][]card4) {
boolean flag = true;
//repeat this nested-loop for card2 and card3 similarly, which I haven't showed in my code.
//The below nested loop are for the condition for the 'if' condition in your code.
for(int j=0; j<5; j++) {
boolean flag1 = true;
for (int i=0; i<4; i++) {
if (card[i][j] == card[i][j+1]) {
}
else {
flag1 = false;
break;
}
}
if (flag1) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
flag = false;
break;
}
}
if (flag) {
int i=0, j=0;
boolean flag2 = true;
while (i<5 && j<5) {
if (i!=2 && j!=2) {
if (card[i][j]==card[i+1][j+1]) {
` }
else flag2 = false;
break;
}
i++;
j++;
}
if (flag2) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
flag = false;
}
else {
i=4;
j=0;
flag2 = true;
while (i<5 && j<5) {
if (i!=2 && j!=2) {
if (card[i][j]==card[i+1][j+1]) {
` }
else {
flag2 = false;
break;
}
}
i--;
j++;
}
if (flag2) {
System.out.println("BINGO! Congratulations, you have won!");
displayBoard(card, card2, card3, card4);
System.exit(0);
flag = false;
}
}
}
return(flag);
}
I have been trying to solve the Wildcard pattern matching and I have found a working solution in the below link:
http://www.geeksforgeeks.org/wildcard-character-matching/
I have written an Equivalent java code for the C code given in the above link, which is:
public class wildcard
{
public static void main(String[] args)
{
test("g*ks", "geeks");
//test("g*k", "gee");
//test("c*d*", "cad");
}
static boolean matches(String format, String data)
{
if (format.length() == 0 && data.length() == 0)
{
return true;
}
if ((format.charAt(0) == '*' && format.charAt(1) != 0 && data.length() == 0) && (format.length() != 0 && data.length() != 0))
{
return false;
}
if ((format.charAt(0) == '?' || format.charAt(0) == data.charAt(0)) && (format.length() != 0 && data.length() != 0))
{
return matches(format.substring(1), data.substring(1));
}
if ((format.charAt(0) == '*')&& (format.length() != 0 && data.length() != 0))
{
return matches(format.substring(1), data) || matches(format, data.substring(1));
}
return false;
}
static void test(String first, String second)
{
System.out.println(matches(first, second));
}
}
On Execution, a String out of bounds Exception is thrown, which is:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:658)
at wildcard.matches(wildcard.java:29)
at wildcard.matches(wildcard.java:36)
at wildcard.matches(wildcard.java:42)
at wildcard.matches(wildcard.java:42)
at wildcard.matches(wildcard.java:36)
at wildcard.test(wildcard.java:52)
at wildcard.main(wildcard.java:16)
I can see that this exception occurs at the CharAt() method, is there any other way to make this work??
:)
First I noticed that the code && (format.length() != 0 && data.length() != 0) is not on the original code from the page you provide and are causing conflicts with your algorithm so I remove it and it looks like this:
static boolean matches(String format, String data) {
if (format.length() == 0 && data.length() == 0) {
return true;
}
if (format.charAt(0) == '*' && format.charAt(1) != 0 && data.length() == 0) {
return false;
}
if (format.charAt(0) == '?' || format.charAt(0) == data.charAt(0)) {
return matches(format.substring(1), data.substring(1));
}
if (format.charAt(0) == '*') {
return matches(format.substring(1), data) || matches(format, data.substring(1));
}
return false;
}
The problems I talked about are in the second condition you have data.length() == 0 and in the code I remove was data.length() != 0, so that condition was always false because the length cannot be 0 and not 0 at the same time.
I discovered two problems. The first one was that some cases like matches("ge?ks*", "geeksforgeeks") end up with having a single wildcard at the format and crashed on if (format.charAt(0) == '*' && format.charAt(1) != 0 && data.length() == 0) because of format.charAt(1). To solve this I add the next code to the algorithm:
if (format.length() == 1 && format.charAt(0) == '*')
return true;
The other problem was when the format was empty but still have data and solve it with:
if (format.length() == 0 && data.length() > 0)
return false;
The final algorithm looks like this:
static boolean matches(String format, String data) {
if (format.length() == 0 && data.length() == 0)
return true;
if (format.length() == 1 && format.charAt(0) == '*')
return true;
if (format.length() == 0 && data.length() > 0)
return false;
if (format.charAt(0) == '*' && format.charAt(1) != 0 && data.length() == 0)
return false;
if (format.charAt(0) == '?' || format.charAt(0) == data.charAt(0))
return matches(format.substring(1), data.substring(1));
if (format.charAt(0) == '*')
return matches(format.substring(1), data) || matches(format, data.substring(1));
return false;
}
Suppose I have 4 variables
String a;
String b;
String c;
String d;
I want to check if individual variable or combination of variable is not Null and act accordingly.
For example one way to do this is using if-else this way
if(a!=null && b == null && c == null && d == null) {
//doSomething }
else if(a==null && b!= null && c == null && d == null) {
//doSomething }
else if(a==null && b!= null && c == null && d == null) {
//doSomething }
else if(a==null && b== null && c != null && d == null) {
//doSomething }
......
//Similarly combination of two variables
if(a!=null && b != null && c == null && d == null) {
//doSomething }
else if(a!=null && b== null && c != null && d == null) {
//doSomething }
else if(a!=null && b== null && c == null && d != null) {
//doSomething }
......
//and so on
//Similarly combination of three variables
if(a!=null && b != null && c != null && d == null) {
//doSomething }
else if(a!=null && b== null && c != null && d != null) {
//doSomething }
else if(a!=null && b== null && c == null && d != null) {
//doSomething }
....
How to achieve this kind of situation Switch even don't accept null
I thought of using queue as it dont allow null values but i need to have a key for the variable so that I can get the value and manipulate something. help will be appreciated
You could build an additional variable to achieve this a with switch statement:
int switchvar = 0;
if (a == null) {switchvar += 1;}
if (b == null) {switchvar += 10;}
if (c == null) {switchvar += 100;}
if (d == null) {switchvar += 1000;}
and then you can use
switch (switchvar) {
case(1): //only a ==null
...
case(101): //a == null and c == null
....
case(1011): //a,b,d null
....
case(1111): // all variables null
}
Running my java code works in debugger but not in run. In the eclipse debugger it shows my jframes.
However when I run it, my frame doesn't appear whatsoever.
I believe I messed up my EventListener and all that.
private class ButtonHandler implements ActionListener{
JButton button;
public void actionPerformed(ActionEvent event) {
find(event.getSource());
button = buttonHolder[indexK[kCount-1]][indexJ[jCount-1]];
if((button.getIcon() == red && choice1 == 1) || (button.getIcon() == green && choice1 == 0)){
JOptionPane.showMessageDialog(null, "You chose the wrong color!");
return;
}
if(turn ==1){
if(clicks != 1){
if(button.getIcon() == red){
clicks++;
temp = button;
}else if (button.getIcon() == green){
clicks++;
temp = button;
}else{
kCount=0;
jCount=0;
}
}else{
if((button.getIcon() == green) || (button.getIcon() == red)){
//do nothing
}else if(temp.getIcon() == green && (grid[indexK[1]][indexJ[1]] == 2 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 4) && button.getIcon() != green && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]-1 == indexJ[1])) ){
temp.setIcon(null);
button.setIcon(green);
grid[indexK[1]][indexJ[1]] = 2;
if(indexK[0] == 0 || indexK[0]== 9){
grid[indexK[0]][indexJ[0]] = 4;
}else{
grid[indexK[0]][indexJ[0]] =3;
}
found = 2;
}else if(temp.getIcon() == red && (grid[indexK[1]][indexJ[1]] == 1 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 5) && button.getIcon() != red && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0]-1 ==indexK[1] && indexJ[0] == indexJ[1]))){
temp.setIcon(null);
button.setIcon(red);
grid[indexK[1]][indexJ[1]] = 1;
if(indexJ[0] == 0 || indexJ[0]== 9){
grid[indexK[0]][indexJ[0]] = 5;
}else{
grid[indexK[0]][indexJ[0]] =3;
}
found = 2;
}
clicks=0;
kCount=0;
jCount=0;
}
}
}
}
}
if you don't see any problems, can you think of a reason why it might be messing up?
First, double check that you're running it in the same mode. A program made for Applet mode is not the same as Application.
If that doesn't work:
If running as an Applet:
Check that you have an init function.
If running as an Application:
Check that you define a main class in your run configuration. If you did, make sure you are running a main() method within it.