In: Computer Science
Thanks in advance.
In Java.
I'm having an issue with one of my methods.
Ex:
The array being pass in is a character array with element: w, ' ', K, Q, k, q, ' ', -, ' ', 0, ' ', 1
public class Find
{
public void enPassant(char[] array)
{
for(int i = 0; i < array.length; ++i)
{
if(array[i] == 'e')
{
count = i;
}
else
{
count += 0;
}
}
if(count > 0)
{
System.out.println("En passant: " + array[count] + array[count +
1]);
}
if(count == 0)
{
System.out.println("En passant: none");
}
}
public class Main
{
public static void main(String[] args)
{
Find testDetail = new Find();
testDetail.enPassant(detailArray);
}
}
Output: Enpassant: kq
My intended output is: Enpassant: none
Why am i getting kq, and what can i do to correct my mistake?
//Find.java public class Find { public void enPassant(char[] array) { int count = 0; for (int i = 0; i < array.length; ++i) { if (array[i] == 'e') { count = i; } else { count += 0; } } if (count > 0) { System.out.println("Enpassant: " + array[count] + array[count + 1]); } if (count == 0) { System.out.println("Enpassant: none"); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////
//Main.java public class Main { public static void main(String[] args) { char arr[] = {'w', ' ', 'K', 'Q', 'k', 'q', ' ', '-', ' ', '1', ' ', '1'}; Find testDetail = new Find(); testDetail.enPassant(arr); } }