हिंदी

Reverse the words of a sentence.

Advertisements
Advertisements

प्रश्न

Reverse the words of a sentence.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clString
{
    public void main()
    {
        Scanner sc = new Scanner(System.in); String ts = "";
        System.out.print("Enter the string : ");
        ts = sc.nextLine();        
        StringTokenizer stoken = new StringTokenizer(ts);
        int t1 = stoken.countTokens();         
        for(int c = 1; c <= t1; c++)
        {
            String word = stoken.nextToken(); 
            int wlen = word.length();            
            for(int k = wlen - 1; k >= 0; k--)
            {
                System.out.print(word.charAt(k));
            }            
            System.out.print(" ");
        }
    }
}

Output:

Enter the string : SNOW IN SHIMLA

WONS NI ALMIHS

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

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
String Handling | Q 4. | पृष्ठ २५३
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×