मराठी

Print the words in a new line each.

Advertisements
Advertisements

प्रश्न

Print the words in a new line each.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clString
{
    public void main()
    {
        Scanner sc = new Scanner(System.in);
        String ts = "", word = "";
        System.out.print("Enter the string : ");
        ts = sc.nextLine();        
        ts = ts + " ";         
        for(int j = 0; j <= ts.length() - 1; j++)
        {
            char ch = ts.charAt(j);            
            if(ch == ' ')
            {
                System.out.println(word); 
                word = ""; 
            }
            else
            {
                word = word + ch; 
            }
        }
    }
}

Output:

Enter the string : ROYAL BENGAL TIGER
ROYAL
BENGAL
TIGER

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 11: Programs Overall - String Handling [पृष्ठ २५३]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×