By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

Help on looping in java

P: 6
Let me first start off by saying I am a beginner at Java. I need help on an assignment to produce a loop which I believe for this particular assignment would be the for loop. The output needs to look like this

N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000

To get this result would I need nested loops also. I appreciate any help on this problem. Thank you.
Oct 29 '06 #1
Share this Question
Share on Google+
3 Replies


P: 6
For this program I started coding it using the For Loop but I am not sure how to show the results under the 4 headers. If somebody can help me I would appreciate it.The output on the screen is suppose to looks like this:

N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000

[/code]public class Forloop
{
public static void main(String[] args)

{
int N;


for ( N = 1; N <= 5; N++)
{

System.out.println(10 * N);

}
for ( N = 1; N <= 5; N++)
{
System.out.println(100 * N);
}
}
}
Oct 30 '06 #2

10K+
P: 13,264
For this program I started coding it using the For Loop but I am not sure how to show the results under the 4 headers. If somebody can help me I would appreciate it.The output on the screen is suppose to looks like this:

N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000

[/code]public class Forloop
{
public static void main(String[] args)

{
int N;


for ( N = 1; N <= 5; N++)
{

System.out.println(10 * N);

}
for ( N = 1; N <= 5; N++)
{
System.out.println(100 * N);
}
}
}
Nested means one inside another not one after another:

Expand|Select|Wrap|Line Numbers
  1. public class Table {
  2.     public static void main (String []args) {
  3.         int n = 1;
  4.         System.out.println("N  10*N   100*N  1000*N");
  5.         for(int j = 1; j <= 5; j++) {
  6.             for(int i = 1; i <= 1000; i = i * 10) {
  7.                 System.out.print(i*j+"    ");
  8.             }
  9.             System.out.println();
  10.         }
  11.     }
  12. }
Oct 30 '06 #3

P: 6
Ok thanks for your help. :)
Oct 30 '06 #4

Post your reply

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