我正在尝试制作一个将英寸转换为英尺的程序,并返回英尺数和剩余的英寸数(如果有)。我尝试了这个:
public class Convertor
{
/**
* Fields
*/
private int inches;
private int feet;
private int yards;
private int leftoverInches;
/**
* Constructor for objects of class Convertor
*/
public Convertor()
{
inches=0;
feet=0;
yards=0;
leftoverInches=0;
}
/**
* Mutator method to convert inches to feet
*/
public void convertValuesInchtoFeet(int anyInches)
{
inches=anyInches;
feet=(anyInches * 0.083);
leftoverInches= inches%feet;
System.out.println(inches+" inches = " +feet+" feet.");
System.out.println("There are " +leftoverinches +" leftover inches");
}
不起作用
请有人帮助我!谢谢。
最佳答案
int inches = 34;
int feet = inches / 12;
int leftover = inches % 12;
System.out.println(feet + " feet and " + leftover + " inches");
关于java - 转换英尺为英寸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5424350/