Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Number pattern in java, 'for' loop

Name: Anonymous 2010-03-02 0:58

Ok, I've been stumped for a while on this program. I am supposed to write a Java program that outputs the following:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Apparently I am supposed to use a "for" loop. I really have no idea what I'm doing:

=================
public class pattern
{
    public static void main(String[] args)
    {
        int num,
            term;  
        System.out.print("\f");       
        for (num=1; num <=9; ++num)
          {}
    }
}
=================

What do you guys think it should be? I know some of you fags are taking Java courses in here somewhere.

Name: Anonymous 2010-03-02 17:45

Just think about what you need to do...

You figured out you need to do 9 runs and right now you're increasing a number. If you look at the example output it's just like a countdown.

Now there should be a way to just count as high as you need in your current iteration.


Don't look below the following line if you actually want to learn something!
==========================
for(i=9;i>0;i--){for(j=0;j<=i;j++){print(j);}print("\n");}

Name: name 2010-03-05 8:47

I don't know Java, but here's how you could do it in QBasic:

REM Program to print pattern
for i = 1 to 10
  if i = 1 then print "1 2 3 4 5 6 7 8 9"
  if i = 2 then print "1 2 3 4 5 6 7 8"
  if i = 3 then print "1 2 3 4 5 6 7"
  if i = 4 then print "1 2 3 4 5 6"
  if i = 5 then print "1 2 3 4 5"
  if i = 6 then print "1 2 3 4"
  if i = 7 then print "1 2 3"
  if i = 8 then print "1 2"
  if i = 9 then print "1"
  if 1 = 0 then print "error, that cannot be happening"
next i

Name: Mbt 2010-04-24 1:04

The Mbt have different variety durability, designs and style, Mbt shoes are technologically highly developed to make your walking exercises more effective, The Mbt sale Now! Free Shipping! NO Tax! http://www.mbt-antishoes.net

Name: renmon 2011-02-06 9:09

for (line =9; line>0; line--)
{
for (col = 1; col <= line; col++)
{
System.out.print(col+ " ");
}
System.out.println();
System.out.println();
}


you can find me here :-)
renmon dot multiply

I am a Freshman IT student. I am looking for people with same interest as mine. That is programming.

Name: renmon 2011-02-06 9:10

renmon.multiply.com

Name: Humphrey 2011-02-07 18:43

If you hear a noise with you milk and your roll
It must be the 10.30 Humphrey patrol
In slippers with pom-poms for creeping about
Watch out, watch out, watch out, watch out
There’s a Humphrey about.
100 Humphrey’s soft as silk
Out on the search for your unigate milk
Get extra pintas or you’ll be without
Watch out, watch out, watch out, watch out
There’s a Humphrey about.

Copy and paste if your milk mysteriously vanishes...

Don't change these.
Name: Email:
Entire Thread Thread List