Untitled
unknown
plain_text
a year ago
882 B
1
Indexable
Never
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int R = scanner.nextInt(); for (int i = 1; i <= R; i++) { // Print the beginning spaces for (int sp = 1; sp <= i - 1; sp++) { System.out.print(" "); } // Iterating from ith column to last column int lastCol = (R * 2 - (2 * i - 1)); // To iterate through column for (int j = 1; j <= lastCol; j++) { if (i == 1 || j == 1 || j == lastCol) { System.out.print("*"); } else { System.out.print(" "); } } // Next line System.out.println(); } } }