473,480 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help writing nested for loop

2 New Member
Hi there. Struggling with this one. I'm to write a program that has this output:

0
10
210
3210
43210
543210
6543210
76543210
876542310
9876543210

Also, I can only have two print statements. One that prints a newline character and one that prints a single digit. I've rearranged my code numerous times and here is what I have now:

public class Loops
{
public static void main (String [] args)
{
for (int num0 = 0; num0 <= 9; num0++)
{
System.out.println();
for (int num1 = 9; num1 >= num0; num1--)
{
System.out.print(num1);
}
}
}
}

This will output:

9876543210
987654321
98765432
9876543
987654
98765
9876
987
98
9

I've also written the code to output:

0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789

Any help is greatly appreciated.
Apr 5 '10 #1
3 3081
tzpike05
2 New Member
No one has any advice?
Apr 5 '10 #2
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
What is the problem you are acing?

Regards
Dheeraj Joshi
Apr 6 '10 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Look at the lines and answer the following:
0
Starts with _, ends with _.
10
Starts with _, ends with _.
210
Starts with _, ends with _.
3210
Starts with _, ends with _.
43210
Starts with _, ends with _.
543210
Starts with _, ends with _.
6543210
Starts with _, ends with _.
76543210
Starts with _, ends with _.
876542310
Starts with _, ends with _.
9876543210
Starts with _, ends with _.

for(START, END, num1--);
Apr 7 '10 #4

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

Similar topics

3
1502
by: Richard A. DeVenezia | last post by:
Can a function write another function that has a specific number of nested loops and then run it? i.e. function maker (N) { // does stuff that creates function doer() // invoke doer doer() }
5
7277
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
46
9863
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
3006
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
5148
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....
3
1459
by: mslyman | last post by:
Hi, I could do with some help. I have this XML. <region> <region_code>567</region_code> <store> <store_code>345</store_code> <dept> <dept_code>32</dept_code> </dept>
13
2062
by: Protoman | last post by:
Here's a non intrusive reference counting smart pointer class I'm working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids declaration of `SmrtPtrDB' with no type" error. Code: ...
2
1818
by: shblack | last post by:
I need help with a program I am writing for school. The program has to do the following: /* 1. Character string must be a minimium of 15 charactors. 2. If not 15 characters long it must give...
5
3105
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...
0
2761
by: LanaR | last post by:
Hello, one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql....
0
7044
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
7045
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
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.