Topics Index

Print Character Formation

If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to print the following character formation using the input String. Spaces in between characters are important. Use System.out.println or System.out.print for printing.

Input (String) Printed Output
antartica a
a n
a n t
a n t a
a n t a r
a n t a r t
a n t a r t i
a n t a r t i c
a n t a r t i c a

class PrintFormation
    public static void main(String s[])


    public static void printFormation(String name)

Topic: charAt() Method In Java - Java Character Extraction

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

here we have to print a string in left triangular form..... no.of rows in series equal to the charactrrs present in the string...... so again we have to use the concept of nested loop... the outrr loop will br for rows and inner loop will befor printng values in each row... now let a=0 to length(name) ..this loop is for rows count take j=0 to a.... we are takimg this comdition as we can see that in each row, no.  of character printed is equal to row no.  ie in frst row only on char is now here print charAt(j) this will print character at postion j.... now outside j loop we will have to give a line change stmt... so that aftr every row control moves to next row. amd now finaly exit outer loop

Posted by Asma Mujtaba Khan    2014-12-15 06:21:45

here we have the same concept which we solved in pattern in the form of rows and here we need nested loops...
here num of rows==name.length();
so tak an for loop loop i control i=0 and i <name.length();
next take an inner for loop j=0 and j<=i;
here print using sop() every time name. charAt(j)
after coming out of the inner loop print the new line Sopln()

Posted by Uday Kumar    2014-12-15 14:16:59

This dose is now closed and the winners are Asma Mujtaba Khan,  for 'First Correct Comment', Uday Kumar,  for 'Second Correct Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-16 04:51:02

© meritcampus 2019

All Rights Reserved.

Open In App