java 我尝试将厘米编程为英寸/英尺 - 英寸到厘米,米
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13211762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I try to program cm to inch/foot - inch to cm,meter
提问by Alex
When i try to compile it, i got an error ";" in line
当我尝试编译它时,出现错误“;” 排队
double cm1 (inch_to_cm*2.54);
It must be in same windows: cm to inch/foot inch to cm/meter.
它必须在相同的窗口中:厘米到英寸/英尺英寸到厘米/米。
import java.util.Scanner;
public class Centimer_Inch
{
public static void main (String[] args)
{
// 2.54cm is 1 inch
Scanner cm = new Scanner(System.in); //Get INPUT from pc-Keyboard
System.out.println("Enter The Centimeters:"); // Write input
double centimeters = cm.nextDouble(); // STAM ???? ?? ????????
double inches = Math.round( (centimeters / 2.54) * 100 ) / 100.0; // STAM ???? ?? ???????? ????? ?2.54
System.out.println(inches +"Inches");
double foot=Math.round( (inches/12) *100) / 100.0;
System.out.print(foot +"Foots");
// inch to cm
Scanner inch1 = new Scanner(System.in);
System.out.println("Enter The Inch");
double inch_to_cm = inch1.nextDouble();
double cm1 (inch_to_cm*2.54); //From INCH TO CM
System.out.println(inch_to_cm);
}
}
回答by JB Nizet
You missed the equal sign:
你错过了等号:
double cm1 = (inch_to_cm * 2.54); //From INCH TO CM
When you want help about an error message from the compiler, tell what the error message is (and try to understand it before posting the question).
当您需要有关来自编译器的错误消息的帮助时,请告诉错误消息是什么(并在发布问题之前尝试理解它)。
回答by kosa
double cm1 (inch_to_cm*2.54); //From INCH TO CM
Should be:
应该:
double cm1 = (inch_to_cm*2.54); //From INCH TO CM
You need to assign results of computation to cm1. =
is assignment operator in java (I hope you know this because you did same in other places)
您需要将计算结果分配给 cm1。=
是 java 中的赋值运算符(我希望你知道这一点,因为你在其他地方也做了同样的事情)
回答by PermGenError
you are not assigning the value to your double variable.
you are missing an =
sign, thus compiler error
您没有将值分配给 double 变量。你缺少一个=
标志,因此编译器错误
double cm1 (inch_to_cm*2.54);
should be
应该
double cm1 =(inch_to_cm*2.54);
回答by Fusky
Also at the end where it says
也在最后它说
System.out.println(inch_to_cm);
it should be
它应该是
System.out.println(cm1);
to be converted back to centimeters.
转换回厘米。