Star pattern Java
1. Print below star pattern in Java
**
***
****
*****
Here is java code to do this
import java.util.*;
class startPatteran{
public static void main(String[] args){
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
class startPatteran{
public static void main(String[] args){
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
2. Print below star pattern in Java
*
**
***
****
*****
Here is code to do this
import java.util.*;
class start2Patteran{
public static void main(String [] args){
for(int i=1;i<=5;i++){
for(int j=0;j<(5-i);j++){
System.out.print(" ");
}
for(int k=1;k<=i;k++){
System.out.print("*");
}
System.out.println();
}
}
}
Comments
Post a Comment