Question: Write a program that will read a line with the first word moved to the end of the line. For ex... 1) Write a program
Write a program that will read a line with the first word moved to the end of the line. For ex...
1) Write a program that will read a line with the first word moved to the end of the line. For example, a possible sample interaction with the user might be
Enter a line of text. No punctuation please.
Java is the language
I have rephrased that line to read:
Is the language java
Assume that there is no space before the first word and that the end of the first word is indicated by a blank, not by a comma or other punctuation.NOTE: Please make the first letter of the first new word upper case and the first letter of the original first word lowercase.
HERE IS WHAT I HAVE SO FAR:
import java.util.Scanner;
public class Ok {
private static Scanner in;
public static void main(String[] args) {
String str;
in = new Scanner(System.in);
System.out.println("Enter a line of text. No puctuation please.");
str = in.nextLine();
int i = str.indexOf(' ');
String word = str.substring(0, i).toLowerCase();
String rest = str.substring(i + 1 ).toUpperCase();
String finalStr = rest + " " + word;
System.out.println("I have rephrased that line to read:");
System.out.println(finalStr);}}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
