需要帮助:计算机科学 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.")
    }
}

括号太多。 改变

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

if (xCoord>0 && yCoord>0) 

与其他人类似。

相关内容

  • 没有找到相关文章

最新更新