small problem ... I need help
I'm very new to Java and I'm getting really good so far in writing codes but i need help with these programs :
how can i print these shapes using for loop :
first shape : (I meant with the numbers to be numbers of spaces )
1234* // this line has 4 spaces
123**
12***
1****
*****
second shape:
----*
---**
--*-*
-*--*
*---*
these are dashes not spaces ... how can i print them using for loops
Re: small problem ... I need help
What have you tried so far?
Re: small problem ... I need help
Code :
public class Test2
{
public static void main(String args[])
{
int count = 1;
int count2 = 1;
for (int i = 5 ; i>= 1; i--)
{
while(count <= (i-1) )
{
System.out.print(" ");
count++;
}
while (count2 <= i-4)
{
System.out.print("*");
count2+=1;
}
System.out.println();
count = 1;
count2 = 1;
}
} }
this is what i tried but it is not working i'd think of it some more but i don't have time I have an exam tommorow and I still have lots of things to study and review and hopefully understand :confused:
I just need a quick solution for these I'm not stupid .. hehehe..
I just don't have time :eek:
I'll really appreciate it if anyone helped me out with them :D
Re: small problem ... I need help
Hi.The first style Loop will be showed below
Code :
public class LoopPrint{
public static void main(String args[]){
int countspace=4;
int countstar=1;
for(int i=0;i<5;i++)
{
int j=countspace;
while(j>0)
{
System.out.print(" ");
j--;
}
int m=countstar;
while(m>0){
System.out.print("*");
m--;
}
System.out.println("");
countspace--;
countstar++;
}
}
}
If you have other problems ,you can send Email to me!
Re: small problem ... I need help
Welcome lewvan00,
se [ ] brackets for code tags, also please keep material on the forums for future use and learning resources as apposed to making them private via emails.
Thanks,
Chris