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