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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
