Question

In: Computer Science

Thanks in advance. In Java. I'm having an issue with one of my methods. Ex: The...

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?

Solutions

Expert Solution

//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);

  }
}


Related Solutions

I'm having a bit of an issue with one of my C++ labs. It's not for...
I'm having a bit of an issue with one of my C++ labs. It's not for score but I need to understand it so I can move on. A restaurant servers burgers for $8 and salads for $7. When the customer selects a burger they must choose if they would like cheese. If they do, cheddar costs an additional 25 cents while pepper jack is 50 cents. When the customer selects a salad they must choose if they would like...
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1)...
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1) Which type of vessels, arteries or veins, has more muscle fibers? What is the functional significance of this? 2a) In general, we have no conscious control over smooth muscle or cardiac muscle function, whereas we can consciously control to some extent all skeletal muscles. Can you consciously control your breathing? What does this tell you about the muscle type of the diaphragm? 2b) What...
I'm having problems with my java code not correctly spellchecking certain words. 1) Determine if a...
I'm having problems with my java code not correctly spellchecking certain words. 1) Determine if a word entered by the user is spelled correctly. A word is considered correct if it's found in dictionary.txt (see required output to get file). these are the input and output that are suppose to come out i already have the dictionary.txt i just don't know hoe to set it up someone please help me Standard Input                 Files in the same directory glimmer hello...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I'm not sure if this is a good issue statement for short case study. Thanks for...
I'm not sure if this is a good issue statement for short case study. Thanks for the help! An American multinational widely diversified media and entertainment organization, Disney Company which started their journey from 1923 are now recognized as one of the most successful enterprise in the century. Bob Iger who has lead the company with his magical, yet fundamental and strong business strategy to overcome the barriers that Disney faced in the last ten years in his career as...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
Is Mental Health a scientific issue? I'm having to write a paper on scientific issues and...
Is Mental Health a scientific issue? I'm having to write a paper on scientific issues and I'm honestly not sure what counts as a scientific issue or not. Could you please also list some other scientific issues in the world today?
Hi guys, I'm working on an assignment for my Java II class and the narrative for...
Hi guys, I'm working on an assignment for my Java II class and the narrative for this week's program has me a bit lost. I've put the narrative of the assignment in the quotation marks below. " Included with this assignment is an encrypted text file. A simple Caesar cipher was used to encrypt the data. You are to create a program which will look at the frequency analysis of the letters (upper and lowercase) to help “crack” the code...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
Im having trouble turning my words and calculations into tables and graphs for my research methods...
Im having trouble turning my words and calculations into tables and graphs for my research methods paper. I need 2 tables and 1 graph. Table 1 - should show that out of 17,425 respondents 43% resported being in business for 3+ years. 33% reported being in business for 1-2 years and 24% respondents being on business for 0-1 years Table 2 - should show marketing method preference. 43% respondent with both online and relationship marketing methods. the 33% group respondent...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT