Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

String Play (JAVA BEGINNER) Implement the following methods: // Write a method that returns true if s has leading or trailing whitespace, false otherwise public

String Play (JAVA BEGINNER)

image text in transcribed

Implement the following methods:

// Write a method that returns true if s has leading or trailing whitespace, false otherwise

public static boolean needsTrim(String s)

// Write a method that swaps the first three and last four characters of s

public static String swap3For4(String s)

// Write a method that has one String parameter, and returns true if the first half and last half of the parameter are the same ignoring case, and false otherwise. (The name of the method is up to you.)

Use these methods to rewrite the corresponding parts of the attached StringPlay program.

import java.util.scanner public class StringPlay public static void main(Stringt1 args) System.out.println("Enter a line of text: " String aLine = kybd.nextLine(); if (aLine.trim).equals (aLine)) System.out.println("The original String has no leading or trailing whitespace") h else t System.out.println("The original String has leading or trailing whitespace" String swapped aLine.substring(aLine.length) - 4) + aLine.substring(3, aLine.length) - 4) + aLine.substring(0, 3); System.out.println("First 3 and last 4 chars swapped: " + swapped) int midPoint-aLine.length) / 2; String firstHalf aLine . substring(0, midPoint); if (aLine. length ( ) % 2-1) midPoint++; String secondHalf - aLine.substring(midPoint); system.out.println("Does the first half equal the last half?" + firstHalf.equalsIgnorecase(secondHalf)) the last half

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_2

Step: 3

blur-text-image_3

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

2. Record these without judgments, criticisms, or comments.

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago