package TaskCh;
//import java.util.Scanner;
public class TaskCh {
public static void main(String[] args) {
// System.out.println("Enter line of text.");
// Scanner kb = new Scanner(System.in);
String s = "London is the capital of UK" ; // kb.nextLine(); // Read the whole line instead of word by word
System.out.println("Original line is : ");
System.out.println(s);
String[] words = s.split("\\s+"); // Split on any whitespace
if (words.length > 1) {
// Swap first and last words
s = words[words.length-1] + " " + s.substring(s.indexOf(words[1], words[0].length() -2 )) + " " + words[0].toLowerCase();
s = s.substring(0, 1).toUpperCase() + s.substring(1); //
}
System.out.println("\n\n\nModified line is :");
System.out.println(s);
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.