Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS WHAT I HAVE import java.util.Scanner; public class Lab4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(Enter a line

THIS IS WHAT I HAVE

import java.util.Scanner; public class Lab4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a line of text: "); // Enter your text String aLine = input.nextLine(); String temp = aLine.trim(); int num = aLine.length(); if (aLine.length() < 7) { System.out.println("The input is too short"); } else { if (aLine.equals(temp)) { System.out.println("the original String has no leading or trailing whitespace"); } else System.out.println("the original String has leading or trailing whitespace."); temp = aLine.substring(num - 5, num) + aLine.substring(2, num - 5) + aLine.substring(0, 2); //Swap the first two and last five characters of aLine and print the result. System.out.println("First 2 and last 5 chars swapped: " + temp); System.out.println("to upper case: " + aLine.toUpperCase()); // uppercase int mid = num / 2; if (num % 2 != 0) { System.out.println("The line has an odd number of characters."); } else { int middle1 = (num - 1) / 2; // first middle int middle2 = num / 2; // second middle char atMiddle1 = aLine.charAt(middle1); char atMiddle2 = aLine.charAt(middle2); System.out.println("The two middle characters are " + atMiddle1 + atMiddle2); } String low = aLine.toLowerCase(); System.out.println("compareTo lower case version: " + aLine.compareTo(low));//compare String firstHalf = aLine.substring(0, mid); String secondHalf = aLine.substring(mid + 1); System.out.println("Does the fist half equal the last half? " + firstHalf.equalsIgnoreCase(secondHalf));// dose first half equal second half } } }

The last thing that I have to do is

"Print aLine with one character removed: The first 'e' 'E' 's' or 'S'." So I will enter a text message and I want a program that will remove the first 'e' 'E' 's' or 'S'. And I have this constraint.

You may use ONLY String's indexOf, charAt, length, compareTo, toUpperCase, toLowerCase, trim, equals, equalsIgnoreCase and substring methods. Sorry if it is hard to read my code. Currently working on making it more organized.

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions