我正在尝试创建一个程序coordinatefinder.java,它向用户询问两个介于1和5之间的整数值。然后,使用一对for循环生成二维坐标平面。平面应为平面上的每个坐标打印一个句点,但用户指定的坐标除外,该坐标应打印一个x。
我要做的事情的例子:
Enter your x coordinate:
2
Enter your y coordinate:
4
5 . . . . .
4 . X . . .
3 . . . . .
2 . . . . .
1 . . . . .
0 1 2 3 4 5
我所拥有的:
import java.util.Scanner;
public class CoordinateFinder {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter an X co-ordinate from 1-5: ");
int x = input.nextInt();
System.out.println("Please enter a y co-ordinate from 1-5: ");
int y = input.nextInt();
for (int i = 5; i >= 1; i--) {
System.out.print(i +" ");
if (i == 0) {
System.out.println("\n");
System.out.println(" 5 4 3 2 1 ");
}
for (int j = 4; j >= 0; j--) {
System.out.print(" . ");
if (j == 0) {
System.out.println("\n");
}
}
}
}
}
哪些输出:
5 . . . . .
4 . . . . .
3 . . . . .
2 . . . . .
1 . . . . .
0
5 4 3 2 1
. . . . .