Help on looping in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dave128
    New Member
    • Oct 2006
    • 6

    #1

    Help on looping in java

    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.
  • Dave128
    New Member
    • Oct 2006
    • 6

    #2
    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.prin tln(10 * N);

    }
    for ( N = 1; N <= 5; N++)
    {
    System.out.prin tln(100 * N);
    }
    }
    }

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Dave128
      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.prin tln(10 * N);

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

      Code:
      public class Table {
      	public static void main (String []args) {
      		int n = 1;
      		System.out.println("N  10*N   100*N  1000*N");
      		for(int j = 1; j <= 5; j++) {
      			for(int i = 1; i <= 1000; i = i * 10) {
      				System.out.print(i*j+"    ");
      			}
      			System.out.println();
      		}
      	}
      }

      Comment

      • Dave128
        New Member
        • Oct 2006
        • 6

        #4
        Ok thanks for your help. :)

        Comment

        Working...