0

此代码确实有效,但不确定是否从中得到正确答案是我使用了错误的公式还是什么?我将论坛放在代码末尾的双行注释中。请不要告诉我添加故障保险柜或任何我想让它不那么混乱的东西。

  public class ICS3URightOnJavaAssignment2c
  {
      public static void main (String[] args) throws Exception
      {
          BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));

          String d; //creates a string variable to get distance (travelled) from user
          double distance = 0.0; //double distance
          System.out.print("Enter distance travelled(KM): ");  //gets distance travelled from user
          d = buffer.readLine(); //reads a line from the console
          distance = Double.parseDouble(d);//gets the double value from string variable d
          System.out.println("Distance Travelled: " + d); //states string variable d

          new BufferedReader(new InputStreamReader(System.in));

          String t; //creates a string variable to get time (travelled) from user
          double time = 0.0; //double time
          System.out.print("Enter time travelled(Minutes): "); //gets time travelled from user
          t = buffer.readLine(); //reads a line from the console
          time = Double.parseDouble(t);//gets the double value from string variable t
          System.out.println("Time Travelled: " + t); //states string variable t

          System.out.println("The average speed (KM/H) with a distance travelled of " + d + and time travelled of " + t + " is " + distance / time);

          /*speed (average) = distance divided by time*/      
      }
  }
4

0 回答 0