Write a program to print the following character pyramid using the input string. Spaces at the beginning of the line and spaces between characters are important. Use System.out.println or System.out.print for printing.
Input (String) |
Printed Output |
India |
I I n I n d I n d i I n d i a |
campus |
c c a c a m c a m p c a m p u c a m p u s |
class PrintFormation
{
public static void main(String s[])
{
printFormation("India");
}
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.
we have to print pattern in row n column form in triangular form....for this firstly we will take a loop for rows ....take I loop i=1 to lengh(name) ....then we will have to take another loop for printing spaces... take j=1 to size(name)-i..,... then in this loop we will print spaces.......then we will take another loop to print characters...... here take k=1 to i's loop....and then print name character at position k and single space... sop(k " ")...
Posted by Asma Mujtaba Khan 2014-12-02 10:48:22
For this we need 3 for loops, main loop is to rotate i = 1 to the given string length,with in this loop we need to write 2 for loops, one is to print spaces and with in this we need to write condition for hire many spaces need to print,I.e j = string length to j > i , and decrement the loop. Second loop for print the characters of the given string so it starts from k = 0 to k < i and increments the loop, to print particular character we use in SOP is String name.charAt() method and along with we should concatenate the space for the required shape. ThanQ
Posted by Damu Surya 2014-12-02 14:43:09
This dose is now closed and the winners are Damodar Ukkadala, for 'First Correct Comment', Asma Mujtaba Khan, for 'Second Correct Comment'. The 'lucky liker' is Shashanka Mogaliraju. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.
Posted by Merit Campus 2014-12-03 03:31:27