Pyramid example
package com.ram; public class Pyramid { public static void main(String[] args) { System.out.println("Program to print a character '*' in the form of a pyramid"); System.out.println("Assuming we need a pyramid of size 10"); //In order to print the triangle, we have to split the triangle into two parts. //The first will have a for loop which will print spaces (" ") //The second will have another for loop which will print "* " for(int i=0; i<10; i++){ for(int j=i; j<10; j++){ System.out.print(" "); } for(int k=0; k<=i; k++){ System.out.print("* "); } System.out.println(); } } }
No comments:
Post a Comment