因此,我正在尝试编写一个代码,生成从顶部 0,0 到 0,5 和横向从 0,0 到 5,0 的坐标,并将其生成到 5,5。这是我想看到的:
(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)
但我无法理解如何做到这一点。这是我当前的代码。
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();
}
}
顺便说一下,我的主要问题是它无法识别,对于 int
这就是我将如何做到的:
for(int a=0; a<=5; a++){
for(int b=0; b<=5; b++){
System.out.print("(" + a + "," + b + ")");
}
System.out.println(" ");
}
在这里,我有两个 for 循环。a
是您的 x 坐标,b
是您的 y 坐标。当a
是 0 时,第二个 for 循环将遍历数字 0-5 给你(0,0) (0,1)...(0,5)
。一旦b
为 5,a 将等于 1,整个过程再次发生,直到(5,5)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句