how to do these Java problems?

<p>how do you write the program so it outputs these shapes?</p>

<p>(1)</p>

<p>1 2 3 4 5
1 2 3 4
1 2 3
1 2
1</p>

<p>(2)</p>

<p>1
2 2
3 3 3
4 4 4 4
5 5 5 5 5</p>

<p>(3)</p>

<pre><code> 1
2 2
3 3 3
</code></pre>

<p>4 4 4 4
5 5 5 5 5 </p>

<p>(4)</p>

<pre><code> 1
2 2 2
3 3 3 3 3
</code></pre>

<p>4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 </p>

<p>Help with these problems~!!!
I know it's done by for but how???</p>

<p>Thanks!</p>

<p>I don't actually take a computer science course but what I would do is something like,</p>

<p>(1)
for(int i = 0; i<5;i++)
{
for(int it = 1;it<=5-i;it++)
{
cout << it;
}
cout << endl;
}</p>

<p>(2)
for(int i = 1; i<=5;i++)
{
for(int it = 1;it<=i;it++)
{
cout << i;
}
cout << endl;
}</p>

<p>(3) (looks the same as 2)</p>

<p>(4)
for(int i = 0; i<5;i++)
{
for(int it = 1;it<=i*2+1;it++)
{
cout << i+1;
}
cout << endl;
}</p>

<p>It looks like you might have lost some formatting, if you did then these wont work but the code should be similar. It's written in C++ so you'll have to convert it which is easy enough really. Just replace cout with System.Console.WriteLine() or whatever it is.</p>

<p>the question somehow changed when posting.</p>

<p>let's assume "*" is blank</p>

<ol>
<li></li>
</ol>

<ul>
<li>* * * 1</li>
<li>* * 2 2</li>
<li>* 3 3 3</li>
<li>4 4 4 4
5 5 5 5 5</li>
</ul>

<ol>
<li></li>
<li>* * * 1 * * * * </li>
<li>* * 2 2 2 * * * </li>
<li>* 3 3 3 3 3 * * </li>
<li>4 4 4 4 4 4 4 *
5 5 5 5 5 5 5 5 5</li>
</ol>

<p>Okay,
(3)
for(int i = 0; i<5;i++)
{
for(int it = 1;it<5-i;it++)
{
cout << " ";
}</p>

<pre><code> for( it = 1;it<=i+1;it++)
{
cout << i+1;
}
cout << endl;
}
</code></pre>

<p>(4)
for(int i = 0; i<5;i++)
{
for(int it = 1;it<5-i;it++)
{
cout << " ";
}</p>

<pre><code> for( it = 1;it<=i*2+1;it++)
{
cout << i+1;
}
cout << endl;
}
</code></pre>

<p>he's right</p>

<p>schoenhs is right</p>

<p>that's using C syntax, of course, so instead of cout << "text", it would be System.out.println "whatever";</p>

<p>As a sidenote, if you haven't done any programming before, or don't know how to compile the program, that's a different question entirely.</p>

<p>-Steve</p>

<p>thanks.
No wonder it's kinda different from what I saw from my book.
Well, I solved those problems~!</p>

<p>What's the hardest problem you guys have ever seen in an AP CS AB course?</p>

<p>no 10 char</p>