I'm having java troubles
Posted: Sat Dec 06, 2014 11:17 am
Hey guys, I'm trying to learn java at the moment at university, and I have run into a slight issue with using for loops.
Basically I have to create this sequence "--***++++-----******+++++++" and this is what I have come up with so far:
I can get the sequence to read out this: 223334444555556666667777777
with this snippet of code
But I am struggling with trying to replace the numbers with the symbols. I think it might involve including conditional statements. I tried this but I think I may have gone wrong with the way I have decided to do it as it reads out this: ++***+++++++++******+++++++
any help would be great
Basically I have to create this sequence "--***++++-----******+++++++" and this is what I have come up with so far:
I can get the sequence to read out this: 223334444555556666667777777
with this snippet of code
Code: Select all
int a, b;
for (a=2;a<8;++a)
{
for (b=1;b<a+1;++b)
{
System.out.print(a);
}
}
Code: Select all
int a, b;
for (a=2;a<8;++a)
{
for (b=1;b<a+1;++b)
{
if (a%3==0)
{
System.out.print("*");
}
else
{
System.out.print("+");
}
}
}