Write a java application that displays the following patterns separately one bel
ID: 3670132 • Letter: W
Question
Write a java application that displays the following patterns separately one below the other.
Use for loops to generate the patterns. There are 4 Triangle patterns.
All asterisks (*) should be printed by a single statement of the form System.out.print('*');
This is 4-different patterns, not 1-pattern.
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********
Explanation / Answer
public class numPtr {
public static void main( String arg[]){
int c=2,d=0;
for(int i=1;i<=10;i++){
for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
for(int i=1;i<=10;i++){
for(int j=10;j>=i;j--){
System.out.print("*");
}
System.out.println();
}
while(c>0){
if(d==0){
for(int i=1,r=10;i<=10;i++,r--){
for(int j=1;j<=r;j++){
System.out.print("*");
}
System.out.println(); }
d++;
} else{
for(int i=1;i<=10;i++){
for(int j=1;j<=i;j++){
System.out.print("*"); }
System.out.println();
}
}
c--;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.