{
for(int j = 0; j <= i; j++)
{
stringBuffer.append(color1);
}
for(int j = i; j <= (size * 5); j++)
{
if(i == 0 || i == (size-1))
{
stringBuffer.append(color2);
}
else
{
stringBuffer.append(color3);
}
}```
#Does anyone know how to reverse this code?
57 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @ionic briar! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
i want to make this
but i currently have this
which is why i want to reverse the code i have posted above (it's the second half of the flag
hahaha
sec
kk cool thanks!
what are color1, color2, color3, size? just so i can get my bearings a bit quicker
also where are you adding newlines?
that doesn't really tell me what i need
also what?
{
StringBuffer stringBuffer = new StringBuffer();
for(int i = 0; i < size; i++)
{
for(int j = 0; j <= i; j++)
{
stringBuffer.append(color1);
}
for(int j = i; j <= (size * 5); j++)
{
if(i == 0 || i == (size-1))
{
stringBuffer.append(color2);
}
else
{
stringBuffer.append(color3);
}
}
stringBuffer.append("\n");
}
for(int i = 0; i < size; i++)
{
for(int j = 0; j <= i; j++)
{
stringBuffer.append(color1);
}
for(int j = i; j <= (size * 5); j++)
{
if(i == 0 || i == (size-1))
{
stringBuffer.append(color2);
}
else
{
stringBuffer.append(color3);
}
}
stringBuffer.append("\n");
}```
why would you not provide the entire code
people have gotten angry at me previously for posting too much code lol
Looks like you shared a lot of code, this may cause people to overlook problems in your code. To make it easier for them, make sure you only share lines that are relevant to your issue.
try having a read at that
in response to this, not your code
the amount of code is fine, it's just really spread out (a lot more newlines than most people would prefer)
it's for comments haha (im dumb and add them in at the end lol)
the main part is you need to show all the relevant stuff
truncate as much excess as you can, but don't remove stuff that's actually important
why do you need to have empty lines prepared though
i need to be very descriptive for the school im in
basically have to describe everything im doing
no, why can't you just add the lines for the comments afterwards
idk tbh, it's just the way ive been doing it
if you aren't going to be commenting along with writing the code, then just focus on the code, worry about comments later
yeah youre right
anyways, you have 2 main loops, both using for (int i = 0; i < size; i++)
each of those correspond to half of the output you have rn
looks like the shape of it is dependant on i, so you need to change how i behaves, the order of values given as i
so the first loop would be unchanged, but for the second loop, since you need to reverse the order of how it iterates, you need to change where i starts and ends accordingly
you need it to iterate opposite the first loop, how can you do that
Would i be changing the starting point of i in the second half of the flag?
yes
for(int i = size ; i > 0; i--)
hows this?
hey you there?
{
for(int j = 0; j <= i; j++)
{
stringBuffer.append(color1);
}
for(int j = i; j <= (size * 5); j++)
{
if(i == 1 || i == (size))
{
stringBuffer.append(color2);
}
else
{
stringBuffer.append(color3);
}
}
stringBuffer.append("\n");
}```
ive made some progress
now i have an extra r sticking out though
how do i get them to shift back once?
sorry
passed out
think of the values that your original loop goes through
suppose size is just 5 for simplicity
the normal loop will go through 0, 1, 2, 3, 4
so you need to reverse that, 4, 3, 2, 1, 0
right now you have 5, 4, 3, 2, 1
@ionic briar