Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: I'm new at this and can't figure it out

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I'm new at this and can't figure it out

    My code is this
    public class temp
    {
    public static void main(String[] args)
    {

    for (int i = 1; i <= 4; i++)
    {
    for (int j = 1; j <= 6; j++)
    {
    System.out.print((i*j)*4-3 + " ");
    }
    System.out.println();
    }
    }
    }
    I'm getting:
    1 5 9 13 17 21
    5 13 21 29 37 45
    9 21 33 45 57 69
    13 29 45 61 77 93

    The output should be:
    1 5 9 13 17 21
    2 6 10 14 18 22
    3 7 11 15 19 23
    4 8 13 16 20 24

    Can't figure out what I'm doing wrong.
    Please help
    Thanks,
    Jeff


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,609
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: I'm new at this and can't figure it out

    Can you describe the algorithm that should be used to generate the desired output?
    The comments in your code are not very helpful.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm new at this and can't figure it out

    I is the row and J is the column.It appears in java that the columns get printed first because that's the inner loop. I'm trying to get it to look like this:
    1 5 9 13 17 21
    2 6 10 14 18 22
    3 7 11 15 19 23
    4 8 13 16 20 24

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,609
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: I'm new at this and can't figure it out

    Can you describe the algorithm that should be used to generate the desired output?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,609
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: I'm new at this and can't figure it out


  6. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm new at this and can't figure it out

    i hope this can help you, i just program it and its look the same with the output of what you want.

    for(int i =1; i<=4;i++)
    {
    for(int j =1; j<=6;j++)
    {
    System.out.printf("%3d", (i * j) * 4 - 3 );
    }
    System.out.println();
    }

Similar Threads

  1. Can not figure out my programs error!
    By mparkerj in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 09:48 AM
  2. can't figure out how to sort an array.
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: February 6th, 2010, 02:07 PM
  3. simple problem w/ appelets which i cant figure out
    By JavaGreg in forum Java Applets
    Replies: 7
    Last Post: August 15th, 2009, 07:22 PM
  4. Generation of Palindrome number in Java
    By tina.goyal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2009, 08:49 AM
  5. [SOLVED] Java program to prompt and display the user input number as odd or even
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 22nd, 2009, 01:19 AM