0% found this document useful (0 votes)
4 views1 page

Computer Java

The document provides a Java program that accepts a user's name and prints a specific pattern based on the characters of that name. It includes code that utilizes loops to format the output correctly. The example given uses the name 'RITIKA' to demonstrate the resulting pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Computer Java

The document provides a Java program that accepts a user's name and prints a specific pattern based on the characters of that name. It includes code that utilizes loops to format the output correctly. The example given uses the name 'RITIKA' to demonstrate the resulting pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

For Class 10 # Created by Prashant Tandon, Computer Teacher, SMC Kanpur # Mobile 9839575830

Answers – String Based Questions


Q4. Write a program to accept a name from the user and print the following Pattern as per
the given name. For Example, Given Name : “RITIKA”

A
A K
A K I
A K I T
A K I T I
A K I T I R

Sample Input Name : “RITIKA” ( Length : 6 )

R I T I K A
0 1 2 3 4 5
Ans. import java . util . * ;
class PatternOnString
{
public static void main( )
{
Scanner SC = new Scanner ( System.in ) ;

System.out.print ( " Enter any Name : " );


String NAME = SC . nextLine( ) ;

System.out.println ( " Given Name : " + NAME );

int len, LINE, N, SP ;


char CH ;

len = NAME.length( ) ;

for( LINE = len-1 ; LINE >= 0 ; LINE -- )


{
for( SP = 1 ; SP <= LINE ; SP ++ )
System.out.print ( "\t" + “ ” );

for( N = len - 1 ; N > = LINE ; N -- )


{
CH = NAME.charAt( N );
System.out.print ( "\t" + CH );
} // end of inner for

System.out.println ( ); // move the cursor to newline


} // end of outer for

} // end of main function


} // end of class

Page No 1 of 1

You might also like