Inverted Stars Pattern Java Programming Code (Using Nested Loop)

Using Nested Loop Inverted Star Pattern

import java.util.Scanner;

public class InvertedStarPattern {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int line = 1; line <= n; line++) {
            // one line
            for (int star = 1; star <= n - line + 1; star++) {
                System.out.print("*");
            }
            System.out.println("");
        }
    }
}

Output: 

7

*******

******

*****

****

***

**

*

No comments:

Post a Comment

Max Sub Array Sum: Kadane's Algorithm

Code of: Max Sub Array Sum: Kadane's Algorithm. public class MaxSubArraySumKadanesALgorithm {     public static void Kadane ( int ...