Question: String Play Write a program using Scanner and its nextLine method. The following is an example of how to use nextLine Scanner kybd = new

String Play

Write a program using Scanner and its nextLine method. The following is an example of how to use nextLine

Scanner kybd = new Scanner(System.in);

System.out.println("Enter a line of text");

String aLine = kybd.nextLine();

You may assume that the user input has at least 7 characters.

Print either "the original String has no leading or trailing whitespace" or "the original String has leading or trailing whitespace." (Hint: the trim method will be a good start, but you'll need more.)

Swap the first three and last four characters of aLine and print the result.

Print aLine in all upper case.

Print the compareTo results of comparing aLine in all lower case with the original aLine. (This will be a number.)

Print whether the first half of aLine is the same as the last half of aLine except for case.

Note: treat each of these steps as an independent action operating on the original input. So if the original input was

kilroy was here, but not godot

swapping the first three and last four characters would print

odotroy was here, but not gkil

and printing aLine in all upper case would result in

KILROY WAS HERE, BUT NOT GODOT

You may use ONLY String's indexOf, charAt, length, compareTo, toUpperCase, toLowerCase, trim, equals, equalsIgnoreCase and substring methods.

Grading Elements

  • Program always uses the original input for each manipulation
  • Program uses only the specified String methods for manipulations
  • Program prints whether the String has leading or trailing whitespace
  • Program tests for any whitespace, not just spaces
  • Program swaps the first three and last four characters
  • Program prints the input in upper case
  • Program prints the results of String's compareTo method pn the original input and the original input converted to lower case
  • Program compares the first half and last half of the input, ignoring case

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!