473,385 Members | 1,901 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,385 software developers and data experts.

Nested For-Loop Problem...Driving me NUTS

Hello, I need to reproduce this pattern using one main for loop and one nested for loop.

0
10
210
3210
43210
543210
6543210
76543210
876543210
9876543210

And here is what I coded, but I can't seem to make it the right way.

Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 10; x++)
  2.          {
  3.              for (int y = 0; y < x; y++)
  4.              {
  5.                  System.out.print(y);
  6.              }
  7.              System.out.println();
  8.          }
Sep 29 '07 #1
5 3783
Ganon11
3,652 Expert 2GB
What output does that give you?
Sep 29 '07 #2
0
01
012
0123
01234
012345
0123456
01234567
012345678

This is what output I get. Close, but no cigar.
Sep 29 '07 #3
hsn
237 100+
this is a way to answer your quesion
<CODE REMOVED. Please read our posting guidelines, especially the section about responding to assignments. .

MODERATOR>
Sep 29 '07 #4
Ganon11
3,652 Expert 2GB
0
01
012
0123
01234
012345
0123456
01234567
012345678

This is what output I get. Close, but no cigar.
OK, it looks like you have half of it down. Now, what can you change about your loops to change the order in which these numbers appear?

HINT: You've seen i++...ever hear of i--? It subtracts 1 from i every time it executes, much like i++ adds one to i every time it executes.
Sep 29 '07 #5
JosAH
11,448 Expert 8TB
0
01
012
0123
01234
012345
0123456
01234567
012345678

This is what output I get. Close, but no cigar.
Have a close look at both loops when they get executed for the first time: x == 0.
The inner loop doesn't print anything at all. Change that '<' sign to '<=' and see
what happens then. I know what happens: the correct number of rows are printed
but the numbers are still wrong: i.e. the digits are printed in increasing order but
you want them in decreasing order. Figure it out.

kind regards,

Jos
Sep 29 '07 #6

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

Similar topics

0
by: Glen | last post by:
I have a Struts action form which contains a bean. I am trying to display a bean retrieved from the database in this form using the nested tag. Can anyone help me? I continue to get an error...
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:...
2
by: newbiecpp | last post by:
Java can declare a static nested class. Does C++ have same thing like? class Outer { public: static class Inner { ... }; .... };
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
6
by: deko | last post by:
How do I construct an XHTML-compliant nested unordered list? This displays correctly (both FF and IE): <ul> <li>list item</li> <li>list item</li> <li>list item</li> <ul> <li>nested list...
7
by: patrick j | last post by:
Hi I'm wondering about lists with nested lists as one does on a Saturday afternoon. Anyway below is an example of a list with a nested list which the iCab browser's very useful HTML...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
5
by: Calvin Spealman | last post by:
On Wed, Aug 13, 2008 at 11:32 AM, Cousson, Benoit <b-cousson@ti.comwrote: There is no point of nested classes because nested classes _are not_ supported by python. They are simply an artifact of...
3
by: Cousson, Benoit | last post by:
I don't think so; my original email was mainly a question. I do agree that they are other ways to do what I'm trying to achieve; there are always several ways to solve an issue. Few days ago, I...
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.