Jump to content

need help with homework

- - - - -

  • Please log in to reply
4 replies to this topic

#1
senor91

senor91

    Newbie

  • Members
  • Pip
  • 2 posts
so i need some assistance in completing the code, i believe im a few steps away from finishing the code. i understand there are two nested loops, i however am having trouble for the last loop. the output i am looking for looks like this:

12345
23451
34512
45123
51234


all help is appreciated
[ATTACH]3731[/ATTACH]

edit: im not sure how to properly post the code on here as i have seen in other threads

Attached Files



#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Take your code and put it inside
 
tags.

As for your PrintSquare method, you need to change the second for loop like this:



	public static void printSquare(int min, int max)

	{

		for (int line=0; line<max-min + 1; line++)

		{

			for (int a=min+line; a<=max; a++)

			{

				System.out.print(a);

			}

			[B][COLOR="red"]for (int b=min; b<min+line; b++)

			{

				System.out.print(b);

			}[/COLOR][/B]

			System.out.println();

		}

	}


That fixes your issue. :)
-CDG10620
Software Developer

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Here it is with 1 inner loop. Possibly a bit harder to undertand tho:

        for (int i = 0; i < 5 ; i++) {

            for (int j = 0 ; j < 5; j++) {

                System.out.print(1+(j+i)%5);

            }

            System.out.println();

        }



#4
senor91

senor91

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks for the help, but i seem to be getting the output of:
123451
234512
345123
451234
512345

which is close, very close now but how would i start the second for loop on the second line?

#5
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
The loop that wim DC posted works perfectly...
-CDG10620
Software Developer




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users