Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions