Initials of string : Recursive Program
A class Initials Print has been defined to print the initials of the name. Some of the members of the class are given below:Class name : InitialsPrintData members/instance variables:String initials : to store the initials of the nameMember functions:initialsPrint(): constructor to assign blank to in
Watch java videos
WAP to print the initials of string recursively.
A class Initials Print has been defined to print the initials of the name. Some of the members of the class are given below:
Class name : InitialsPrint
Data members/instance variables:
String initials : to store the initials of the name
Member functions:
initialsPrint(): constructor to assign blank to initials. Downloaded from
void initRecursive(String s, int i): to store the initials of the name in the variable initials as shown in the sample output using Recursive technique.
Sample Input: Narendra Damodardas Modi
Sample Output: N.D.M.
display(): to accept full name from the user and print the initials
of string as shown in the sample output.
Specify the class Initials Print the initials of string giving details of the constructor, void initRecursive(String s, int i) and void display(). Write main() to create and object and call the respective methods.
import java.util.*;
public class InitialsPrint
{
String initials;
InitialsPrint()
{
initials="";
}
void initRecursive(String s,int i)
{
if(i<s.length())
{ char ch=s.charAt(i);
if(ch == ' ')
initials+=s.charAt(i+1)+".";
initRecursive(s,i+1);
}
}
void display()
{
System.out.println("The Initials of the string are ");
System.out.println(initials);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String sen=sc.nextLine();
sen=" "+sen;
InitialsPrint obj=new InitialsPrint();
obj.initRecursive(sen,0);
obj.display();
}
}
Download free Sample papers
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.