65 875
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #23758 in Java | JSP | JSF for linda

Question #23758
Write a program that displays the following pattern:

*
***
*****
*******
*****
***
*

Output. Seven lines of output as follows: The first consists of 3 spaces followed by a star. The second line consists of 2 spaces followed by a 3 stars. The third consists of one space followed by 5 stars, and the fourth consists just of 7 stars. The fifth line is identical to third, th sixth to the second and the seventh to the first.

CLASS NAMES. Your program class should be called StarPattern
Expert's answer
public class StarPattern {

publicstatic void main(String[] args) {
finalint rows = 7;
intspaces = rows/2;
intstars = 1;
for(inti = 0; i < rows; i ++){
for(intj = 0; j < spaces; j ++){
System.out.print("");
}
for(intj = 0; j < stars; j ++){
System.out.print("*");
}
System.out.println();
if(i< rows/2){
spaces--;
stars+= 2;
}
else{
spaces++;
stars-= 2;
}
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions