Nested Loops Star Pattern Java Programming java code

Simple Java Code for Star Pattern.

import java.util.Scanner;

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

Output: 

java .\StarPatternUsingNastedLoops.java

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 ...