Skip to content

Instantly share code, notes, and snippets.

@urvil38
Last active July 26, 2017 03:08
Show Gist options
  • Select an option

  • Save urvil38/bb84de4a0d21e2736e2e69c466a1512c to your computer and use it in GitHub Desktop.

Select an option

Save urvil38/bb84de4a0d21e2736e2e69c466a1512c to your computer and use it in GitHub Desktop.
simple pyramid program in java
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