Program - 1
public class Pattern{
public static void main(String[]args){
for (int i=1;i<=4;i++)
{
for (int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
for (int i=1;i<=3;i++){
for (int j=3;j>=i;j--){
System.out.print("*");
}
System.out.println();
}
}
}
Output
Program : 2
public class Pattern1
{
public static void main(String[]args)
{
for (int i=1;i<=5;i++){
for (int j=1;j<=5;j++){
if (j<i)
{
System.out.print(" ");
}
else {
System.out.print("*");
}
}
System.out.println();
}
}
}
Output
Program - 3
for(int i=1;i<=5;i++){
for (int j=1;j<=5;j++){
if (i>=2&&j>=2&&i<=4&&j<=4)
{
System.out.print(" ");
}
else {
System.out.print("*");
}
}
System.out.println();
}
}
}
Output
click me for more star pattern programs
pick for you :
- Generics Class and Methods
- String and String builder and String Buffer
- Linked Hash Set
- Linked Hash Map
- Exception Handling
- Array Class and Array List
- Important Programs
- Searching
- Sorting
- Array Sorting
No comments:
Post a Comment