I am supposed to create a method called compareParity which compareParity that takes a Scanner containing words as its parameter. The method should return true if the Scanner contains more strings of even length than strings of odd length, and false otherwise. For example,

compareParity(new Scanner("The quick brown fox jumped over"))

should return false.

here is my code so far

public static boolean compareParity()

    {

    Scanner S = new Scanner(System.in);
    {
        int ne=0, no=0;
        while(S.hasNext())
        {
        int X=S.next().length();
        if(X%2==0)ne++;
        else no++;
        }

        return (ne>no);
        }
        }

public static void main(String[] args) {
        compareParity();
    }

What I am doing wrong ?

The requirement includes a parameter thats passed to the compareParity method, but your method has no parameters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.