- 2

Write a program in Java to accept a sentence in lower case and make the first and last letter of each word capital.

Sample input -i love my school Sample output- I LovE MY SchooL

11th Sep 2019, 1:26 PM
Dinesh Kumar
Dinesh Kumar - avatar
2 Respostas
+ 2
import java.io.*; import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner in=new Scanner(System.in); String s=in.next(); char ch; if(s.toLowerCase().equals(s)){ for(int i=0;i<s.length();i++){ if(i==0){ ch=Character.toUpperCase(s.charAt(i)); s.replace(s.charAt(i),ch); } if(i!=s.length()-1){ if(s.charAt(i+1)==' '){ ch=Character.toUpperCase(s.charAt(i)); s.replace(s.charAt(i),ch); } } if(s.charAt(i)==' '&&i!=s.length()-1){ ch=Character.toUpperCase(s.charAt(i+1)); s.replace(s.charAt(i+1),ch); } if(s.charAt(i)!=' '&&i==s.length()-1){ ch=Character.toUpperCase(s.charAt(i)); s.replace(s.charAt(i),ch); } } } System .out.println (s); } }
11th Sep 2019, 2:26 PM
KfirWe
KfirWe - avatar
+ 3
https://www.sololearn.com/Discuss/1316935/?ref=app If you are asking for help in making this kind of program then first show you attempt. Otherwise please don't post this here it ain't the place for this.
11th Sep 2019, 1:50 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar