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

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.