Last active
July 26, 2017 03:08
-
-
Save urvil38/bb84de4a0d21e2736e2e69c466a1512c to your computer and use it in GitHub Desktop.
simple pyramid program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| class pyramid{ | |
| void printPyramid(String str){ | |
| int l = str.length(); | |
| for(int i=0 ; i< l ; i++){ | |
| for(int k = 1 ; k < str.length() - i ; k++){ | |
| System.out.print(" "); | |
| } | |
| for(int j = 0 ; j <= i ; j++){ | |
| System.out.printf("%c ",str.charAt(j)); | |
| } | |
| System.out.print("\n"); | |
| } | |
| } | |
| } | |
| class Main { | |
| public static void main(String args[]) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Please enter string:"); | |
| String str = sc.nextLine(); | |
| pyramid p = new pyramid(); | |
| p.printPyramid(str); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment