Jump to content

Nested loop *Help*

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
nishanjo

nishanjo

    Newbie

  • Members
  • Pip
  • 2 posts
i am new in java...so some one can plez help me..

Round Data
2 2 4
3 3 6 9
4 4 8 12 16

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
a little explanation please? What exactly must happen?

#3
nishanjo

nishanjo

    Newbie

  • Members
  • Pip
  • 2 posts
i need output like this...

2 2 4
3 3 6 9
4 4 8 12 16

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts

public class Looping {

    private String string="";


    public Looping() {

        for(int j=2 ; j<5 ; j++) {

            string= ""+j+" ";


            for(int i=1 ; i!=j+1 ; i++){

                string+=""+ j*i +" ";

            }

            

            System.out.println(string);

        }

    }

}


Main if you need it:

public static void main(String[] args) {

        Looping loop = new Looping();

    }


#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Oxano, we don't usually help people unless they show an effort.

If you are confused with nested loops you might want to look up a reference on how loops work. There is nothing special about a loop but a loop inside another loop.

There are some examples here: http://forum.codecal...p-examples.html
Nested for loops for C++

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Sorry, being too friendly again ;)

#7
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
It's fine! :)

#8
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
i don't know java, but you would have something like this: in some kind of pseudo-code
for i = 2 to 4 do:
  print i + " "
  for j = 1 to 3 do:
    print i*j + " "

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall