-2

我为标题中的问题编写了代码,似乎遇到了一些问题。谁能给我一些关于我做错了什么的见解或提示。尤其是代码的“if...else”部分。

这是问题#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.")
    }
}
4

1 回答 1

4

括号太多了。改变

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

if (xCoord>0 && yCoord>0) 

和其他人一样。

于 2013-09-21T22:58:36.687 回答