我正在研究一個允許用戶輸入x和y的程序。用戶輸入x和y之後,程序會將這兩個點顯示爲一個有序對,並告訴用戶該點位於哪個象限內,如果它位於y軸的左側或右側,並且該點位於下方或上方x軸。輸出的一些例子將包括:關於我的程序關於圖上的一個點的問題
Enter x: 3.4
Enter y: -8.2
Point: (3.4, -8.2)
The point is below the x-axis.
The point is to the right of the y-axis.
The point lies in quadrant IV.
Enter x: 3
Enter y: 0
Point: (3, 0)
The point is on the x-axis.
The point is to the right of the y-axis.
Enter x: 0
Enter y: 0
Point: (0, 0)
The point is on the origin.
這裏是我的代碼
import java.util.Scanner;
public class Graph
{
public static void main(String[] args)
{
//declare variables
int x;
int y;
Scanner reader = new Scanner (System.in); // set up scanner to read user inputs
// prompt x and y
System.out.print ("Enter x:");
x = reader.nextInt();
System.out.print ("Enter y:");
y = reader.nextInt();
//display point
System.out.println("\nPoint: ("+x+","+y+")");
//determine where the point is on a graph
if(x > 0 || x < 0 && y > 0)
System.out.println("\nThe point is above the x-axis.");
else
if (x > 0 || x < 0 && y < 0)
System.out.println("\nThe point is below the x-axis.");
if(x < 0 && y > 0 && y < 0)
System.out.println("\nThe point is to the left of the y-axis.");
else
if (x > 0 && y > 0 && y < 0)
System.out.println("\nThe point is to the right of the y-axis.");
else
if(x < 0 && y < 0)
System.out.println("\nThe point is in Quadrant III.");
else
if(x < 0 && y > 0)
System.out.println("\nThe point is in Quadrant II.");
else
if (x > 0 && y > 0)
System.out.println("\nThe point is in Quadrant I.");
else
if (x > 0 && y < 0)
System.out.println("\nThe point is in Quadrant IV.");
if (x == 0 && y == 0)
System.out.println("\nThe point is at the origin.");
if (y==0 && x < 0 || x > 0)
System.out.println("\nThe point is on the x-axis.");
else
if (x==0 && y < 0 || y > 0)
System.out.println("\nThe point is on the y-axis.");
}// end class
}
爲我種我將不勝感激幫助的鐵鏽使用java,謝謝! :)
究竟是什麼問題?您需要充分描述您的問題併發布任何相關錯誤。 – 2014-09-30 23:21:08
@BoristheSpider哦,是的,我忘了包括這一點。那麼當我編譯它說沒有錯誤,但是當我運行程序並鍵入(2,2)例如它給我 點:(2,2) 點是在x軸上方 點在象限我 點是在x軸 當我運行(3,0) 點是x軸 點是在x軸 它並沒有真正的工作之上正確的是我想說的 – jugo 2014-09-30 23:24:35
@ jugo你應該編輯問題來添加任何附加信息。 – 2014-09-30 23:26:26