How do I print this out using for loops?: ....* ...** ..*** .**** ***** .**** ..*** ...** ....* Without the "...." just the "*". It's like in a diamond shape.
for(int i = 1; i <= 5; i++) { for(int j = 1; j < i; j++) { for(int a = 4; a = a+1 ; a--) ///////I give up. { } System.out.print("*"); } System.out.println(); }
hmmm just trying to clarify... ....* ...** ..*** .**** .***** .**** ..*** ...** ....* and not ....* ..*** ***** ..*** ....* cuz if you're gonna be spacing out the asterisk with a space " " it's gonna be offset. only thing i can think of that might work is: ....* ...* * ..* * * .* * * * * * * * * .* * * * ..* * * ...* * ....* is that what you were looking for? it depends what results you want, so we can help you with getting the method for the proper result
This: ....* ...** ..*** .**** ***** .**** ..*** ...** ....* Replace the "..." with spaces. This is too hard. I believe you have to do this in two parts.
jon, i corrected my post. in the courrier font, the width of all characters are equal. ....* ...* * ..* * * .* * * * * * * * * .* * * * ..* * * ...* * ....* you notice how there is a space between each asterisks? my concern is not the spacing of "...." my concern is trying to properly space out so that: ....* ...* * there is one * on top of two **, and centered. do you see?
The space between the asterisks doesn't matter because when you do a print out, you can print it out like: System.out.print("* "); or System.out.print("*"); It's easy to change between the two. The first post doesn't have space between asterisks.
lol thanks jon. i am fully aware of that fact. but i was not talking about spaces after the end of a string. I know it doesn't. i was trying to get clarification from OP to make sure there was no mistake in understanding the question. my question still remains: how do you get half a space? you can't. which brings me to the idea that if there are spaces between the asterisks, you provide each row with an odd number of characters, which will allow you to CENTER one row on top of another.
HAHAHAHA, I didn't think about that. -woot2 Ya, you need a space between the asterisks. I think you have to use: System.out.print("* ");
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool o...The way the asterisks are displayed here, made me think they are centered...o looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool (lol around the sentence)
if you can manage to use the absolute value then it'll work. i havent c++ for a while. but if you can manage to set the j = 5 - abs(x). abs(x) is the # of dots and j is the number of stars. work something with it. it should work
Made this assignment 4 years ago too lol... /* At the execution, give a integer as argument. If you using linux at terminal then => for example : java Diamant 8 Something like this will work you need to include the math class too */ Code: public class Diamant{ public static void main(String[] args) { int N = Integer.parseInt(args[0]); for (int i = -N; i <= N; i++) { for (int j = -N; j <= N; j++) { if (Math.abs(i) + Math.abs(j) <= N) System.out.print("* "); else System.out.print(" "); } System.out.println(); } } } /* output Code: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if you want this then delete the extra space sign @ System.out.print("* "); and (" ) => Code: * *** ***** ******* ********* ******* ***** *** * */
lol, that's with rows containing odd numbers: * *** ***** *** * the same can be applied to increments of one * ** *** ** *
Sorry, I didn't know when I post this, the spacing between the stars disappear in a regular post. Code: * * * * * * * * * * * * * * * * * * * * * * * * *