1.

Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string. Sample input: we are in cyber world Sample output : We Are In Cyber World

Answer»

import java.io.*; 

import java.util.Scanner; 

class ChangeLetter { 

public static void main(String args[ ]) throws IOException { 

Scanner sc = new Scanner(System.in); 

System.out.print(“Enter String in lowercase:”); 

String str 1 = sc.next( ); strl = “” +strl; 

String str2 = ” “: 

for (int i = 0; i<strl.lenght(); i+ +) {

if(strl ,charAt(i) = = “) { 

str2 = str2 + ” +Character. 

toUpperCase(strl.charAt(i+l)); i+ + ; 

}. 

else str2= str2 + strl.charAt(i); 

System.out.println(str2.trim( )); 

}



Discussion

No Comment Found

Related InterviewSolutions