Computer Science, asked by shubham0987654321, 9 months ago

WAP to assign 3 letter name and display the initials of the first two words. For ex input:Mohandas Karamchand Gandhi. output:M.K.Gandhi use java program​

Answers

Answered by madhumadhurya9
0

Answer:

import java.util.*;

class wrdarray

{

   Scanner sc=new Scanner(System.in);

   int i,l,k=0,c=0,arr;

   char ch;String a[]=new String[100];

   String name="",nes="",sp="";

   void input()

   {

       System.out.println("Enter the string");

       name=sc.nextLine();

       name=name+" ";

   }

   void cal()

   {

       l=name.length();

       for(i=0;i<l;i++)

       {

           ch=name.charAt(i);

           if(ch==' ')

           {

               nes=name.substring(k,i);

               a[c++]=nes;

               k=i+1;

           }

       }

   }

   void dis()

   {

       char ar1=a[0].charAt(0);

       char ar2=a[1].charAt(0);

       String news= ar1+"."+ar2+"."+a[2];

       System.out.println("The new String is " +news);

   }

   public static void main()

   {

       wrdarray ob=new wrdarray();

       ob.input();

       ob.cal();

       ob.dis();

   }

}

Explanation:

Using arrays!

Output:

Enter the string

Mohandas Karamchand Gandhi

The new String is M.K.Gandhi

Please do mark this as Brainliest!

Similar questions