Java 我的扫描器好像不能用了

Java 我的扫描器好像不能用了,java,Java,我不明白为什么我的扫描仪不工作;我也不会出错。我的工作是要求用户输入所有点。真的,我被卡住了,这将在几个小时内完成,而且我正在使用最新的eclipse和新的JDK。新的编程和这个网站XD 当我运行程序时,我得到了这个结果;我也没有收到任何错误 欧几里得:3.847076812334269 象限:点p位于Y轴,点q位于原点 坡度:14.16668您需要更新提示并删除不必要的扫描仪来解决问题。您的提示都要求输入“first”值,而keyboard1-keyboard3从未使用过。此代码同样适用: i

我不明白为什么我的扫描仪不工作;我也不会出错。我的工作是要求用户输入所有点。真的,我被卡住了,这将在几个小时内完成,而且我正在使用最新的eclipse和新的JDK。新的编程和这个网站XD

当我运行程序时,我得到了这个结果;我也没有收到任何错误 欧几里得:3.847076812334269 象限:点p位于Y轴,点q位于原点
坡度:14.16668

您需要更新提示并删除不必要的扫描仪来解决问题。您的提示都要求输入“first”值,而keyboard1-keyboard3从未使用过。此代码同样适用:

import java.util.*;
import java.util.Scanner;
import java.io.*;


class Point
{
   /* Method to find the quadrant of both the points p and q*/

   public String quadrant(double xp, double yp, double xq, double yq){


        Scanner keyboard= new Scanner(System.in);
        System.out.print("Enter the first value for Xp: ");
        xp = keyboard.nextDouble();
        Scanner keyboard1 = new Scanner(System.in);
        System.out.print("Enter the first value for Yp: ");
        yp = keyboard.nextDouble();
        Scanner keyboard2= new Scanner(System.in);
        System.out.print("Enter the first value for Xq: ");
        xq = keyboard.nextDouble();
        Scanner keyboard3= new Scanner(System.in);
        System.out.print("Enter the first value for Yq: ");
        yq = keyboard.nextDouble();
       String p_quadrant=getQuadrant(xp,yp);
       String q_quadrant=getQuadrant(xq,yq);
       return "Point p is at "+p_quadrant+" and Point q is at "+q_quadrant;  
   }

   /* Method to get the quadrant of each passed point*/
   public String getQuadrant(double x, double y){
       if(x==0 && y==0){
           return "Origin";
       }
       else if(x==0){
           return "Y-axis";
       }
       else if(y==0){
           return "X-axis";
       }
       if (x >= 0) {
   return (y >= 0 ? "1st Quadrant":"4th Quadrant");
       } else {
return (y >= 0 ? "2nd Quadrant":"3rd Quadrant");
   }

   }
   /* Method to get the euclidean distance between p and q */
   public double euclidean(double xp, double yp, double xq, double yq){
   double euc_distance = 0.0;

   double x_square=Math.pow((xq-xp), 2);
   double y_square=Math.pow((yq-yp), 2);
   euc_distance= Math.sqrt(x_square+y_square);

   return euc_distance;
   }

   /* Method to calculate the slope */
   public double slope(double xp, double yp, double xq, double yq){

       double x_diff= xp-xq;
       double slope=0.0;

       /* Check applied to avoid a divide by zero error */
       if(x_diff == 0){
           System.out.println("Slope is undefined");
           System.exit(1);  
       }
       else{
           slope=(yp-yq)/x_diff;
       }
       return slope;  
   }


   public static void main (String[] args) throws java.lang.Exception
   {

   /* Creating an object of Points and calling each method individually and printing the value*/
   Points p = new Points();
   double euc=p.euclidean(2.3, 5.6,0.5,9);
   String quad=p.quadrant(0, -5.6,0,0);
   double slop=p.slope(0,0.5,0.6,9);
   System.out.print("Euclidean:"+euc+"\n Quadrant:"+quad+"\n Slope:"+slop);
   }
}

另外,在main方法中,创建Points()对象而不是创建Point()对象。这确实给了我一个错误

“我的扫描仪不工作”一点也不描述您的问题。您需要清楚地描述“什么不工作”,包括预期的输出和代码中出现的任何错误/错误的位置。可能的重复您只需要一个扫描仪对象。另外,你甚至不使用额外的。现在我在类点上得到一个错误,它说“类型点已经定义了。”nvm正在工作,但我的结果现在是错误的;扫描仪正在工作,但现在未使用“我的值”。输入Xp:20的第一个值输入Yp:21的第一个值输入Xq:36的第一个值输入Yq:23的第一个值欧几里德:3.847076812334269象限:p点在第一象限,q点在第一象限斜率:14.16668我不太确定你得到的是什么。您需要解释您期望的输出,并更清楚地了解问题。我从上面的代码中可以看到:getQuadrant()方法由一系列if()语句组成。您输入的数字都大于1,因此执行的代码是第38-40行的if()语句。这就是为什么你会得到“象限1”作为你价值观的回报。除此之外,你还需要提供更多关于你想要完成的事情的细节。希望有帮助。祝你好运
Scanner keyboard= new Scanner(System.in);
    System.out.print("Enter the first value for Xp: ");
    xp = keyboard.nextDouble();
    System.out.print("Enter the first value for Yp: ");
    yp = keyboard.nextDouble();
    System.out.print("Enter the first value for Xq: ");
    xq = keyboard.nextDouble();
    System.out.print("Enter the first value for Yq: ");
    yq = keyboard.nextDouble();
    String p_quadrant=getQuadrant(xp,yp);
    String q_quadrant=getQuadrant(xq,yq);
    return "Point p is at "+p_quadrant+" and Point q is at "+q_quadrant;
}