2013-09-21 68 views
-2

我在標題中編寫了問題代碼,似乎遇到了一些問題。任何人都可以給我一些見解或提示我做錯了什麼。特別是使用代碼的「if ... else」部分。需要幫助:計算機科學101硬件/ JAVA

以下是問題#9。如果您點擊鏈接,它會向您顯示問題的打印輸出。 http://s21.postimg.org/nl2tmf5tj/Screen_Shot_2013_09_21_at_6_44_46_PM.png

這裏是我的代碼:

import java.util.*; 
public class Ch3Ex9 { 
/** 
* This method asks user for an x,y coordinates of a point, then returns the 
* distance to the origin and which quadrant the point is in. 
*/ 
public static void main(String[] args) 
{ 
    double xCoord; //x Coordinant initialized to 3 
    double yCoord; //y Coordinant initalized to 4 
    double hypo; //hypotenuse 

    //declare an instance of Scanner to read the datastream from the keyboard 
    Scanner keyboard = new Scanner(System.in); 

    //get x Coordinant from the user 
    System.out.print("Please enter the X coordinant: "); 
    xCoord = keyboard.nextDouble(); 

    //get Y Coordinate from the user 
    System.out.print("Please enter the Y coordinant: "); 
    yCoord = keyboard.nextDouble(); 

    //calculate the hypotenuse which is the length to the origin 
    hypo = Math.hypot(xCoord, yCoord); 
      System.out.println("The hypotenuse is "+hypo); 

    //determine which Quadrant the user-inputted point resides in 
    if (xCoord>0) && (yCoord>0) // 
     System.out.println("Point lies in Quadrant I."); 
    else if (xCoord<0) && (yCoord>0) 
     System.out.println("Point lies in Quadrant II."); 
    else if (xCoord<0) && (yCoord<0) 
     System.out.println("Point lies in Quadrant III."); 
    else if (xCoord>0) && (yCoord<0) 
     System.out.println("Point lies in Quadrant IV.") 
    } 
} 
+1

如果Y == 0 --->位於X軸線上。如果X == 0 --->位於Y軸線上。 0 ---> center(不屬於任何象限?) –

+2

如果你不解釋問題是什麼,要幫助你解決你遇到的問題是非常困難的。 –

回答

4

有太多的括號內。更改

if (xCoord>0) && (yCoord>0) 

if (xCoord>0 && yCoord>0) 

,同樣與他人。

+0

非常感謝!有用!!! – zhughes3