我有这个非常具体的编程任务。我需要仅使用循环和if语句来绘制x轴和y轴,并且它所在的方法只能返回字符串,不管是轴,还是空字符串“”。我有它几乎正确,但我不明白为什么Y轴不在x == 0打印,但在x == -10。我很想知道如何解决这个问题,我相信这是我忽略的一些小问题。它确实有效,我返回“”而不是“”,但我不允许这样做。谢谢!使用循环和字符串绘制X和Y轴
public class Try1 {
public static void main(String[] args) {
int height = 10;
int width = 10;
for (int y = height; y >= -10; y--){
for (int x = -10 ; x <= width; x++){
DrawAxis(x,y);
System.out.print(DrawAxis (x,y));
}
System.out.print("\n");
}
}
public static String DrawAxis(int x, int y)
{
if (x == 10 && y == 0)
return ">";
else
if (x == 0 && y == 10)
return "^";
else
if (x == 0 && y == 0)
return ".";
else
if (x == 0 && y >= -10)
return "|";
else
if (x >= -10 && y == 0)
return "-";
return "";}
}
你究竟想要画什么形状? – dosdebug 2014-10-03 23:54:43
我想在20乘20的空间中画两条轴线(如十字)。 – 2014-10-04 01:30:44