0
How to fix this?(not solved)
I want to make this in the shape of a diamond.. 3/4 successful... But 1/4 does matter😅😅 Problem is on the second space loop... (for loop) https://code.sololearn.com/cafU3MhS2XbE/?ref=app
7 Answers
+ 3
public class Program
{
int start;
int end;
public void calc(){
int sp = 0;
int space = 10;
//Incrementing loop(first half)
for(int i = 10;i>=1;i--){
for(int j = 1;j<=i;j++){
System.out.print("*");
}
//Space loop 1
for(int j = 1;j<=sp;j++){
System.out.print(" ");
}
sp+=2;
start = i;
//Decrementing loop(second half)
for(int j = start;j>=1;j--){
System.out.print("*");
}
System.out.println();
}
//Incrementing loop:First half(Down)
for(int i = 1;i<=10;i++){
for(int j = 1;j<=i;j++){
System.out.print("*");
}
//Space loop 2
for(int j = 0;j<space-1;j++){
System.out.print(" ");
}
space--;
//Decrementing loop
end = i;
for(int j = end;j>=1;j--){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
Program obj = new Program();
obj.calc();
}
}
+ 3
Changes made:
" "->" "
j<=space -> j<space-1
+ 2
⏩ Prometheus ⏪
Can you explain? 😅😅
space loop 2
+ 2
Can't explain much! Haha
Okay here is what I went through.
To mirror it our I need 2 times the number of spaces.
Then after that I just removed 4 spaces from each line as it was misaligned.
0
I don't think it worked...
0
In line 58: j<10-i;
In line 60: System.out.print("two spaces in these quotes");
0
Nope it's not working