Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*; import java.util.*;
- public class Pyramid{
- public static void Pyramid(){
- Scanner kbReader = new Scanner(System.in);
- System.out.println();
- System.out.print("pyramid word - ");
- String PyramidWord = kbReader.nextLine( );
- System.out.print("number of lines to print (whole number) - ");
- int lines = kbReader.nextInt() + 1;
- int incr = 1;
- String a = PyramidWord + " ";
- int alength = a.length();
- int StringLength = PyramidWord.length();
- int line = 0;
- int linelength = lines;
- int freespaces = -1;
- int spaces = freespaces;
- int detspaces = spaces;
- System.out.println();
- while (line <= lines){
- while (freespaces >=0){
- System.out.print(" ");
- freespaces -= 1;
- }
- detspaces += alength/2;
- spaces = detspaces;
- while (spaces >= -1){
- System.out.print(" ");
- spaces -= 1;
- }
- linelength -= 1;
- incr = 1;
- while (incr <= linelength){
- System.out.print(a);
- incr += 1;
- }
- System.out.println();
- line += 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement