1 The program will accept a string as input in which all of

1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string \"StopAndSmellTheRose\" would be converted to \"Stop and smell the roses\". Display the result string.

2. Then the program will convert each word in the result string of task 1 into \"Pig Latin\" and display the result string. In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending \"ay\" to the word.

For example, for the result string \"Stop and smell the roses\" in task 1, the Pig Latin string should be \"topSay ndaay mellsay hetay osesray\"

Requirements:

Solution

// save it as Test.java

import java.lang.*;
public class Test{

public static void main(String []args){
String s = \"thisIsMyString\";
String st = splitByUppercase(s);
System.out.println(\"Seperated by Upper case: \ \"+st);
System.out.println(\"To Pig Latin: \ \"+ PigLatin(st));
  
}
public static String splitByUppercase(String s) {
String[] r = s.split(\"(?=\\\\p{Upper})\");
String st = String.join(\" \", r);
return st;
}
public static String PigLatin(String s) {
if (s == null) return null;
String[] st1 = s.toLowerCase().split(\" \");
String st2 = \"\";
int i = 0;
while (i < st1.length) {
st2 = \"bcdfghjklmnpqrstvwxz\".contains(\"\" + st1[i].charAt(0))
? String.valueOf(st2) + st1[i].substring(1, st1[i].length()) + st1[i].charAt(0) + \"ay\"
: String.valueOf(st2) + st1[i] + \"yay\";
if (i != st1.length - 1)
st2 = String.valueOf(st2) + \" \";
++i;
}
return st2;
}
}

output:

Seperated by Upper case:                                                                                                                                         

this Is My String                                                                                                                                                

To Pig Latin:                                                                                                                                                    

histay isyay ymay tringsay

1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site