(Solved) : Write Program Using Scanner Nextline Method Following Example Use Nextline Scanner Kybd Ne Q44136349 . . .
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();
If the user’s input is shorter than 7 characters, print themessage “The input is too short” and do no further processing. Ifthe user’s input is 7 characters or longer, perform the followingoperations.
Print either “the original String has no leading or trailingwhitespace” or “the original String has leading or trailingwhitespace.” (Hint: the trim method will be a good start, butyou’ll need more.)
Swap the first two and last five characters of aLine and printthe result.
Print aLine in all upper case.
If aLine has an odd number of characters, print “The line has anodd number of characters.” Otherwise, print the two middlecharacters of aLine.
Print the compareTo results of comparing aLine in all lower casewith the original aLine. (This will be a number.)
Print whether the first half of aLine is the same as the lasthalf of aLine except for case.
Print aLine with one character removed: The first ‘e’ ‘E’ ‘s’ or’S’.
Note: treat each of these steps as an independent actionoperating on the original input. So if the original input was
kilroy was here, but not godot
swapping the first two and last five characters would print
Godotlroy was here, still waiting for Ki
and printing aLine in all upper case would result in
KILROY WAS HERE, BUT NOT GODOT
You may use ONLY indexOf, charAt, length, compareTo,toUpperCase, toLowerCase, trim, equals, equalsIgnoreCase andsubstring methods.
sample output from my solution is
Enter a line of text: This line starts with a blankThe original String has leading or trailing whitespaceFirst 2 and last 5 chars swapped: blankhis line starts with a Tto upper case: THIS LINE STARTS WITH A BLANKThe two middle characters are rtcompareTo lower case version: -32Does the fist half equal the last half? falsethe input with first ‘e’ or ‘E’ or ‘s’ or ‘S’ removed: Thi line starts with a blankEnter a line of text: Kilroy was here, still waiting for GodotThe original String has no leading or trailing whitespaceFirst 2 and last 5 chars swapped: Godotlroy was here, still waiting for Kito upper case: KILROY WAS HERE, STILL WAITING FOR GODOTThe two middle characters are ilcompareTo lower case version: -32Does the fist half equal the last half? falsethe input with first ‘e’ or ‘E’ or ‘s’ or ‘S’ removed: Kilroy wa here, still waiting for GodotEnter a line of text: reiterate reiterateThe original String has leading or trailing whitespaceFirst 2 and last 5 chars swapped: erateeiteratereit rto upper case: REITERATE REITERATEThe two middle characters are e compareTo lower case version: 0Does the fist half equal the last half? truethe input with first ‘e’ or ‘E’ or ‘s’ or ‘S’ removed: riterate reiterate
Expert Answer
Answer to Write a program using Scanner and its nextLine method. The following is an example of how to use nextLine Scanner kybd =…
OR