मराठी

Write a program for the following. Input a string (in lower case) and capitalise the 2nd letter of each word of the sentence.

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Input a string (in lower case) and capitalise the 2nd letter of each word of the sentence.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clTask
{
   void main()
   {
      String s1 = "", s2 = "";
      char ch1, ch2;
      Scanner sc = new Scanner(System.in);
      System.out.print(" Enter a sentence in lower case : ");
      s1 = sc.nextLine();
      s1 = " " + s1; // putting a leading space
      for(int j = 0; j<= s1.length() – 1; j++)
      {
           ch1 = s1.charAt(j);
           if(ch1='')
           {
              ch2 = s1.charAt(j + 2);
              ch2 = Character.toUpperCase(ch2);
              s2 = s2 + ch1 + s1.charAt(j + 1) + ch2;
              j =j + 2;
           }
           else
              s2 = s2 + ch1;
      }
      System.out.println("Modified String is : " + s2);
   }
}

Output:

Enter a sentence in lower case : failures are the pillars of success Modified String is: fAilures aRe tHe pIllars oF sUccess

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 10: String Handling - Exercises [पृष्ठ २४८]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 10 String Handling
Exercises | Q 4. (b) | पृष्ठ २४८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×