- 1

I DIDMT GET A OUTPUT PLZ.. ANY ONE..TRY THIS

package com.mkyong; import java.util.Collections; public class CreatePyramid { public static void main(String[] args) { int rows = 5; System.out.println("\n1. Half Pyramid\n"); for (int i = 0; i < rows; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); } System.out.println(""); } System.out.println("\n2. Full Pyramid\n"); for (int i = 0; i < rows; i++) { for (int j = 0; j < rows - i; j++) { System.out.print(" "); } for (int k = 0; k <= i; k++) { System.out.print("* "); } System.out.println(""); } //java 8 , one line System.out.println("\n3. Full Pyramid (Compact)\n"); for (int i = 0; i < rows; i++) { System.out.println(String.join("", Collections.nCopies(5 - i - 1, " ")) + String.join("", Collections.nCopies(2 * i + 1, "*"))); } // java 8 System.out.println("\n4. Inverted Pyramid\n"); for (int i = rows; i > 0; i--) { System.out.println(String.join("", Collections.nCopies(5 - i, " ")) + String.join("", Collections.nCopies(2 * i - 1, "*"))); } } }

13th Aug 2017, 1:50 AM
ROSHAN SHETTY
ROSHAN SHETTY - avatar
2 Answers
+ 3
Works here in CodePlayground if you remove the line @Michal PĂĄcal indicated.
13th Aug 2017, 2:48 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
[answering from head] I thing it have to do something with that "package" thing. Your main is in the class CreatePyramid, witch isn't projects main class so your main doesn't get called. Just try removing the package line and name .java file same as class
13th Aug 2017, 2:08 AM
Michal PĂĄcal
Michal PĂĄcal - avatar