5th sem OOPJ Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows.


import java.util.Scanner;

/**
 *
 * @author Yash
 */

public class pra9 {
    public static void main(String arg[]){
        char c;
        int i,j,k;
        Scanner sc = new Scanner(System.in);
        String s1;
        System.out.print("Enter the String :");
        s1=sc.next();
        for(i=0;i<s1.length();i++){
            for(j=0;j<=s1.length()-i;j++){
                System.out.print(" ");
            }
            for(k=0;k<=i;k++){
                c = s1.charAt(k);
                System.out.print(c+" ");
            }
            System.out.println(" ");
        }
    }
}

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab1: Create a Database Table for DayCare

SQL Lab 11