1
我需要在用戶輸入的行和列的星號數的網格,到目前爲止,我有這樣的:電網和x和y座標
import java.util.Scanner;
public class Grid {
public void run(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the grid width (1-9):");
double num = scan.nextDouble();
System.out.println("Enter the grid length (1-9)");
double numLength = scan.nextDouble();
for(int i = 0; i < num; i++){
for(int j = 0; j < numLength; j++){
System.out.print("*");
}
System.out.println("");
,但我不知道該怎麼在網格的(0,0)中插入一個字符'X',左上角或如何使其移動,甚至可以循環。用戶必須放置「向上」「向下」「左」和「右」才能移動,並且我非常困惑於如何在java中使用x和y座標。
裏面你的循環,'x'是'j'和'y'是'我'。就如此容易。 – 2013-02-22 07:40:30