Java 尝试为象限I绘制轴,取而代之的是象限IV

Java 尝试为象限I绘制轴,取而代之的是象限IV,java,Java,目前,我正在尝试创建一个程序,在15x15象限I(坐标平面)网格中的任意位置绘制一个正方形。我一直在努力使轴正确显示 这是我迄今为止的代码: import java.util.Scanner; public class Question2square { public static void main(String[] args) { // Axis variables int yAxismin = 0; int yAxismax = 15; int xA

目前,我正在尝试创建一个程序,在15x15象限I(坐标平面)网格中的任意位置绘制一个正方形。我一直在努力使轴正确显示

这是我迄今为止的代码:

import java.util.Scanner;

public class Question2square {
  public static void main(String[] args) {

    // Axis variables
    int yAxismin = 0;
    int yAxismax = 15;
    int xAxismin = 0;
    int xAxismax = 15;

     //Loop through all coordinates on plane using for loops

    for(int y = yAxismin; y <= yAxismax; y++)
    {
      for(int x = xAxismin; x <= xAxismax; x++)
      {
        //Draw the axis 
        if (!Axis(x,y).equals("")) {
          System.out.print(Axis (x,y));
        }
      }
    System.out.println("");
    }
  }
  // This method draws the 15x15 axis
  public static String Axis(int x, int y)
  {
   // Each if and else if statement dictates what symbol needs to go where for the axes
  // If there is nothing to be drawn, there will simply be a blank space
    if (x == 15 && y== 0) return ">";    
    else if(x == 0 && y == 15) return "^";     
    else if (x == 0 && y == 0 )return ".";    
    else if(x == 0 && y >= 0) return "|";    
    else if(x >= 0 && y==0) return "-";    
    else return "";    
  }  


/*  
// Method to be used to draw actual square
  public static ... drawSquare(...) {
  }
*/
}
import java.util.Scanner;
公开课问题2{
公共静态void main(字符串[]args){
//轴变量
int-yAxismin=0;
int yAxismax=15;
int-xAxismin=0;
int xAxismax=15;
//使用for循环遍历平面上的所有坐标
对于(int y=yAxismin;y=0)返回“|”;
否则,如果(x>=0&&y==0)返回“-”;
否则返回“”;
}  
/*  
//用于绘制实际正方形的方法
公共静态…drawSquare(…){
}
*/
}
不幸的是,它没有绘制我想要的“L”形轴,而是显示了“r”形。我想知道如何正确显示轴


我试着翻转for循环,但没用。我看不出还有什么能阻止这一点。

尝试反转
y
循环:

for(int y = yAxismax; y >= yAxismin; y--) ...
当您的循环从“上到下”再从“左到右”将行打印到控制台时,您希望最大的
y
值排在第一位,最小的
x
值排在第一位。因此,您只需反转
y
循环即可从
yAxismax
转到
yAxismin
。结果(对于
3
和非
15
的限制)为:

^ | | .--> ^ | |
.-->这里有一个很好的例子,虽然它不是您想要的:啊!成功了!我以前尝试过切换y的起始位置,但忽略了将字符串更新从“y++”更改为“y-->。再次感谢Andy!这里的响应速度和质量给我留下了深刻的印象。对于我可能造成的麻烦,我深表歉意!现在我要经历抽签了D:@KommanderKitten。不需要道歉。你会奖励那些帮助你的人,通过投票选出好的答案,并通过点击复选标记来标记你问题的最佳答案——这也会为你接受的每个答案获得分数。