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 4 of 4

Thread: loop for in for in for

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default loop for in for in for

    this is my problem


    for(int i=1;i<15 ;i++) // start and write *
    {//repeat
    System.out.println("*");

    for(int j=0 ;j<i<6;j++) // write " / " from 1 to 6
    { System.out.print("/"); }
    for(int h=7;h<i;h++) // write " + " from 7 to end =15
    {System.out.print("+"); }

    --- Update ---

    I want it this this shape but in one code not two

    for(int i=1;i<6 ;i++)
    {//repeat
    System.out.println("*");
    for(int j=0 ;j<i;j++) {
    System.out.print("/");}}


    for(int k=6;k<15 ;k++)
    { System.out.println("*");
    for(int h=0;h<k;h++) {
    System.out.print("+");}}

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: loop for in for in for

    this is my problem
    Can you explain in more detail what your problem is?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Also make sure the code is properly indented. For example:
          for(int i=0; i < 9; i++)
          {
             //
             for(int j=0; j < 3; j++) 
             {
                //
             }
          }
    Unformatted code is hard to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: loop for in for in for

    thanks I found it

    for(int i=1;i<15 ;i++)
    {//repeat
    System.out.println("*");
    for(int j=0 ;j<i & i<6;j++) {
    System.out.print("/");
    }
    for(int h=0;h<i & i>5;h++) {
    System.out.print("+");
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: loop for in for in for

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. loop once or loop multiple times
    By stanlj in forum Loops & Control Statements
    Replies: 3
    Last Post: November 7th, 2013, 02:14 PM
  2. For loop, the first command in the loop does not get executed the 2nd time..
    By lina_inverse in forum Loops & Control Statements
    Replies: 1
    Last Post: October 16th, 2012, 09:00 PM
  3. [SOLVED] Please help with my while loop that turned into infinite loop!
    By Hazmat210 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 10th, 2012, 11:22 PM
  4. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  5. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM