如何使用时间和行进距离获得平均速度

时间:2013-09-28 18:11:45

标签: java

此代码确实有效,但我不确定是否从中获得了正确的答案我使用了错误的公式或其他什么?我将论坛放在代码末尾的双线评论中。请不要告诉我添加故障保险箱或任何我希望保持不那么混乱的保险箱。

  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*/      
      }
  }

0 个答案:

没有答案
相关问题