हिंदी

Write a program in Java to enter a sentence. Frame a word by joining all the first characters of each word of the sentence. Display the word. Sample Input: Vital Information Resource Under - Computer Applications

Advertisements
Advertisements

प्रश्न

Write a program in Java to enter a sentence. Frame a word by joining all the first characters of each word of the sentence. Display the word.

Sample Input: Vital Information Resource Under Seize
Sample Output: VIRUS

कोड लेखन

उत्तर

import java.util.*; 
public class SQ8 
170 
{ public static void main(String h[]) 
{ 
String ns = ""; 
System.out.println("Enter the string"); 
Scanner sn = new Scanner(System.in); 
String s = " " + sn.nextLine(); 

for (int j = 0; j < s.length(); j++)
{ if (s.charAt(j) == ' ')
ns += s.charAt(j + 1); // the first letter after space
}

System.out.println(ns); 
}}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: String Handling - EXERCISES [पृष्ठ २९०]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 4 String Handling
EXERCISES | Q IX. 8. | पृष्ठ २९०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×