如何編寫一個程序,提示並讀取速度和距離的整數值,然後使用eclipse將該行程所需的時間打印爲java中的浮點數結果如何計算Java中的速度和距離
import java.util.Scanner;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class Lab3 {
public static void main(String[] args) {
int time = 0;
int distance = 0;
int speed = distance/time;
float fval = speed * time;
double dval = distance/speed;
String message;
Scanner scan = new Scanner(System.in);
System.out.println("Please Enter Your Avaerage Speed: ");
message = scan.nextLine();
System.out.println("You Entered: \"" + message + "\"");
System.out.println("Your Total Speed is: ");
到目前爲止你寫的代碼是什麼? –
import java.util.Scanner; import java.text.DecimalFormat; import java.text。NumberFormat的; 公共類{Lab3的 \t公共靜態無效的主要(字串[] args){ \t \t INT \t時間= 0; \t \t int distance = 0; \t \t int speed = distance/time; \t \t float fval = speed * time; \t \t double dval = distance/speed; \t \t \t \t \t \t \t 字符串\t消息; \t \t Scanner scan = new Scanner(System.in); System.out.println(「請輸入您的Avaerage速度:」); \t \t message = scan.nextLine(); \t \t \t \t System.out.println(「You Entered:\」「+ message +」\「」); \t \t \t System.out.println(「Your Total Speed is:」); –
它崩潰了。我的控制檯無法獲取數據或輸入 –