不知何故,輸出結果完全錯誤。有任何解決這個問題的方法嗎?我怎樣才能將米轉換爲英里,並用英尺和英寸來表示餘數?
import java.util.Scanner;
public class MeterConversion {
public static void main(String[] args) {
int meters;
System.out.print("Enter meters: ");
Scanner userInput = new Scanner (System.in);
meters = userInput.nextInt();
double inches = (3.3 * 12 * meters);
int feet = (int) (inches/12);
int miles = (feet/5280);
int milesConversion = (miles - (meters % miles));
int feetConversion = ((miles - milesConversion) % feet);
int inchesConversion = (int) (feetConversion % inches);
System.out.print(meters + " meter(s) converts to "
+ milesConversion +" mile(s), " + feetConversion + " feet, "
+ inchesConversion + " inch(es)");
}
}
仰望int劃分。 –
請包括一個例子(你的輸入和輸出) – Spencer4134
@HovercraftFullOfEels不是int division其實就是這裏的要點,OP想要轉換爲全部英里,其餘部分以英尺和英寸爲單位?我認爲使用int分解從英尺到整英里是合適的。我懷疑問題是進一步下降,用'*轉換'變量,並試圖找出剩下的腳。 –