The Artima Developer Community
Sponsored Link

Java Answers Forum
code required for nested for loops

4 replies on 1 page. Most recent reply: Oct 5, 2003 1:00 PM by FredrikN

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Tony

Posts: 3
Nickname: maximus
Registered: Oct, 2003

code required for nested for loops Posted: Oct 5, 2003 3:30 AM
Reply to this message Reply
Advertisement
i'm sure this will be simple to some of the more advanced programmers but I need some code that will produce the following list of numbers as I am only starting it would be much appreciated

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: code required for nested for loops Posted: Oct 5, 2003 8:06 AM
Reply to this message Reply
Post the code you already have? then lets see how we can help you from there onwards

FredrikN

Posts: 22
Nickname: fredrikn
Registered: Jul, 2003

Re: code required for nested for loops Posted: Oct 5, 2003 8:21 AM
Reply to this message Reply
After 60 seconds of coding, and I'm far away from the pro staus :-)

public class Driver
{
	public static void main(String[] args)
	{
		//The number of iterations you want to do
		int loop = 6;
		
		for(int i = 1 ; i <= loop  ; i++)
		{
		
			for(int y = 1 ; y <= i ; y++)
			{
				System.out.print(y+" ");
			}
		
			System.out.println();		
					
		}
			
	}
	
}

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: code required for nested for loops Posted: Oct 5, 2003 10:32 AM
Reply to this message Reply
FredrikN, I really don't think it's good just to give people code. How else can they learn?

FredrikN

Posts: 22
Nickname: fredrikn
Registered: Jul, 2003

Re: code required for nested for loops Posted: Oct 5, 2003 1:00 PM
Reply to this message Reply
Well, you have a point there.
I will think twice next time :-)

Flat View: This topic has 4 replies on 1 page
Topic: Swing vs. AWT Previous Topic   Next Topic Topic: Really need help on java assignment please!!!!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use