473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need help in Nested Loops...

Please help if you can.

Print the following patterns using nested loops. Output should be in separate programs.

Pattern 1

1
12
123
1234
12345
123456

Pattern 2

123456
12345
1234
123
12
1

Pattern 3

1
21
321
4321
54321
654321

Pattern 4

123456
12345
1234
123
12
1
Feb 15 '08 #1
6 4096
hirak1984
316 100+
Please help if you can.

Print the following patterns using nested loops. Output should be in separate programs.

Pattern 1

1
12
123
1234
12345
123456

Pattern 2

123456
12345
1234
123
12
1

Pattern 3

1
21
321
4321
54321
654321

Pattern 4

123456
12345
1234
123
12
1

so did you try yourself?
please post the code that you have written.
we will correct it, and add something if needed.
Feb 15 '08 #2
Ganon11
3,652 Expert 2GB
There is also an interesting article in the Howtos section under Java having to do with this type of problem.
Feb 15 '08 #3
BigDaddyLH
1,216 Expert 1GB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

Then when you are ready post a new question in this thread.

MODERATOR
Feb 15 '08 #4
so did you try yourself?
please post the code that you have written.
we will correct it, and add something if needed.

I'm very new in Programming.
This is what I've done but the output is only 111111....1.
I try to insert char current = '1', '2', '3', '4', '5', '6' but it wouldn't work also.
I know my understanding in Programming is really terrible. Please help.
Thanks.



public class Alphabet
{
public static void main(String[] args)
{
char current = '1';
for(int row = 1; row <= 10; row++)
{
for(int column = 1; column <= 10; column++)
{
System.out.print(current + " ");
}
}
}
Feb 17 '08 #5
BigDaddyLH
1,216 Expert 1GB
Suggestion: use int not char. It may make it more obvious how to get from 1 to 2 to 3 to 4 to 5!
Feb 17 '08 #6
JosAH
11,448 Expert 8TB
I'd suggest you write two small methods up(int n) and down(int n). The first method
prints a line 123 ... n and the second method prints a line n ... 321 where 'n'
is the value of the parameter you pass to the method.

e.g. your first problem can be desribed as up(1), up(2), up(3) ... up(6) which
screams for a simple single loop again. You can figure out the other shapes yourself.

kind regards,

Jos
Feb 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
9
by: Gregory Petrosyan | last post by:
I often make helper functions nested, like this: def f(): def helper(): ... ... is it a good practice or not? What about performance of such constructs?
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Could someone give me a simple example of nested scope in C#, please? I've searched Google for this but have not come up with anything that makes it clear. I am looking at the ECMA guide and...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
13
by: Fredrik Lundh | last post by:
Patrol Sun wrote: so why exactly are you trying to nest 20 or 100 for-in loops? </F>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.