हिंदी

Write a program for the following. Input a string (in lower case) and convert only the vowels to upper case.

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Input a string (in lower case) and convert only the vowels to upper case.

कोड लेखन
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();
       for(int j= 0; j<= s1.length() – 1; j++)
       {
            ch1 = s1.charAt(j);
            if(ch1='a' || ch1='e' || ch1=' ' || ch1='o’ || ch1='n')
            {
                 ch2 = Character.toUpperCase(ch1);
                 s2 = s2 + ch2;
            }
            else
            {
                 s2 = s2 + ch1;
            }
       }
       System.out.println("Modified String is: " + s2);
   }
}

Output:

Enter a sentence in lower case : success is sweet only if you sweat for it

Modified String is : sUccEss Is swEEt Only If yOU swEAt fOr It

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 10: String Handling - Exercises [पृष्ठ २४८]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×