// Pyramids.java (c) Kari Laitinen // http://www.naturalprogramming.com // 2021-09-04 File created. /* This program demonstrates: - definition and calling of a static method */ import java.util.* ; class Pyramids { // Here we specify a static method that will be called later. // This method takes one parameter (argument) // The internal statements of the method will be executed only // when it is called. static void print_pyramid( int desired_number_of_levels ) { if ( desired_number_of_levels > 2 && desired_number_of_levels < 21 ) { for ( int level_counter = 1 ; level_counter <= desired_number_of_levels ; level_counter ++ ) { System.out.print( "\n" ) ; // New line for new level // We'll print space characters so that the top of the pyramid will be // close to the character position 40. for ( int space_counter = 0 ; space_counter < 40 - level_counter ; space_counter ++ ) { System.out.print( " " ) ; // print a single space character } // The body of the pyramid will consist of double characters "==" for ( int double_character_counter = 0 ; double_character_counter < level_counter ; double_character_counter ++ ) { System.out.print( "==" ) ; // print double character } } } else { System.out.print( "\n Number of pyramid levels not acceptable. \n" ) ; } System.out.print( "\n" ) ; } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; // Here we make calls to the above static method print_pyramid( 18 ) ; // print a pyramid with 18 levels print_pyramid( 10 ) ; // print a smaller pyramid } }