please help convert this pseudo code to java
Code:
string toprint = "";
// for each row
for(int row=0; row<n; row++){
toprint = "";
if(row==0){
// leading spaces = n/2
foreach(0 to n/2) toprint += " ";
toprint += "*";
}
else if((row>0)&&(row<n/2)){
// leading spaces = n/2 - row number
foreach((n/2)-row) toprint += " ";
// 3 stars in each row>0 && row < n/2
for(int i=0; i<3; i++){
toprint +="*";
string spaces = "";
// spaces between stars = row number -1
foreach(0 to row-1) spaces += " ";
toprint += spaces;
}
}
else if(row==n/2){
foreach(0 to n){
toprint += "*";
}
}
else if((row>n/2)&&(row<n-1)){
foreach(0 to row-(n/2)) toprint += " ";
// 3 stars in each row>n/2 && row < n-1
for(int i=0; i<3; i++){
toprint +="*";
string spaces = "";
// spaces between stars = n - row number-2
foreach(0 to n-row-2) spaces += " ";
toprint += spaces;
}
}
else if(row==n-1){
// leading spaces = n/2
foreach(0 to n/2) toprint += " ";
toprint = "*";
}
toprint += "\n";
}
print(toprint);
Re: please help convert this pseudo code to java
That is absolutely not how this works. What have you tried? Where are you stuck?
Re: please help convert this pseudo code to java
Quote:
Originally Posted by
KevinWorkman
That is absolutely not how this works. What have you tried? Where are you stuck?
I've tried to do it but it didn't give me the shape it's so hard problem i tried so many answers and it just won't come out here it is Assignment01_9553.pdf
Re: please help convert this pseudo code to java
Few folks are going to click on a link. If you need our help, post your code here in the forum along with any error messages or misbehaviors.