javadrjava

How do I use For Loops to generate coordinates from 0,0 to 5,5?


So i'm trying to write a code that generates coordinates from 0,0 to 0,5 across the top and from 0,0 to 5,0 across the side and that will generate it to 5,5. This is what I want to see:

(0,0) (0,1) (0,2) (0,3) (0,4) (0,5)

(1,0) (1,1) (1,2) (1,3) (1,4) (1,5)

(2,0) (2,1) (2,2) (2,3) (2,4) (2,5)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5)

(4,0) (4,1) (4,2) (4,3) (4,4) (4,5)

(5,0) (5,1) (5,2) (5,3) (5,4) (5,5)

But I can't understand how to do that. Here is my current code.

public class MCassignment14
{
  public static void main(String[] args)
  {
    System.out.print("\n\n");
    System.out.print("Coordinates\n"
                       + "-------\n\n");

    for (int d = (0,0); d <= ((0,5); d++)
    {

      for (int c = (0,0); c <= ((5,0); c++)
      {
        System.out.print("\t" + (c*d));
      }
      System.out.print("\n");
    }
    System.out.print();
  }
}

And by the way my main issue is its not recognizing , for an int


Solution

  • This is how I would do it:

      for(int a=0; a<=5; a++){
          for(int b=0; b<=5; b++){
            System.out.print("(" + a + "," + b + ")");
          }
          System.out.println(" ");
        }
    

    Here, I have two for loops. a is your x coordinate and b is your y coordinate. When a is 0 the second for loop will run through the numbers 0-5 to give you (0,0) (0,1)...(0,5). once b is 5, a will equal 1 and the entire process happens again until (5,5).