Question: Java: User enters a sequence of Strings. If the word is longer than the word to it's left AND the word is considered a double

Java:

User enters a sequence of Strings. If the word is longer than the word to it's left AND the word is considered a double word, the count increases. For example, defdef would count as a double word, but catdog would not.

I've started working through it, but am getting stuck in figuring out how to find both stipulations. I only need the portion between the bold letters. This is the code I've tried working though.

import java.util.Scanner; import java.util.ArrayList;

public class Test {

public static void main(String[] args) { Scanner stdin = new Scanner(System.in); // your code starts here ArrayList words = new ArrayList(); int cnt = 0; while (stdin.hasNext()){ words.add(stdin.next()); } for(int i=0; i < words.size(); i++){ String word = words.get(i); int length = word.length(); int half = length/2; String wordPart1 = word.substring(0, half + 1); String wordPart2 = word.substring(half + 1); if(wordPart1.equals(wordPart2) && words.get(i).length()

// your code ends here System.out.println(cnt); stdin.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!