Skip to Content

Java Pyramid 6 Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Java Pyramid 6 Example
  3.         This Java Pyramid example shows how to generate pyramid or triangle like
  4.         given below using for loop.
  5.        
  6.         *****
  7.         ****
  8.         ***
  9.         **
  10.         *
  11.         *
  12.         **
  13.         ***
  14.         ****
  15.         *****
  16.  
  17. */
  18.  
  19. public class JavaPyramid6 {
  20.  
  21.         public static void main(String[] args) {
  22.                
  23.                 //generate upper half of the pyramid
  24.                 for(int i=5; i>0 ;i--){
  25.                        
  26.                         for(int j=0; j < i; j++){
  27.                                 System.out.print("*");
  28.                         }
  29.                        
  30.                         //create a new line
  31.                         System.out.println("");
  32.                 }
  33.                
  34.                 //generate bottom half of the pyramid
  35.                 for(int i=1; i<= 5 ;i++){
  36.                        
  37.                         for(int j=0; j < i; j++){
  38.                                 System.out.print("*");
  39.                         }
  40.                        
  41.                         //create a new line
  42.                         System.out.println("");
  43.                 }
  44.  
  45.         }
  46. }
  47.  
  48. /*
  49.  
  50. Output of the example would be
  51. *****
  52. ****
  53. ***
  54. **
  55. *
  56. *
  57. **
  58. ***
  59. ****
  60. *****
  61.  
  62. */