所以我的程序工作正常,直到它必须计算结束然后显示结果。它只显示结果而不计算"如果"最后。
public class Convertisseur1 {
public static void main(String[] args) {
String valeurInitial;
String valeurPoid;
String valeurDesire;
String valeurInitial2;
String valeurInitial3;
//seperation des string
valeurInitial = (args[0]);
valeurInitial2 = (args[0]);
valeurDesire = (args[1]);
valeurInitial3 = (args[0]);
valeurInitial = valeurInitial.replace("kg","");
valeurInitial = valeurInitial.replace("g","");
valeurInitial = valeurInitial.replace("t","");
valeurInitial = valeurInitial.replace("lb","");
double valeurdouble = Double.parseDouble(valeurInitial);
valeurInitial2 = valeurInitial2.substring(valeurInitial2.length()-2);
valeurInitial3 = valeurInitial3.substring(valeurInitial3.length()-1);
//convertion
System.out.println(valeurInitial2);
System.out.println(valeurDesire);
System.out.println(valeurdouble);
if(valeurInitial2 == "kg" &&valeurDesire == "g"){
valeurdouble = (valeurdouble*1000);
System.out.println("La convertion finale : " + valeurdouble);
}else if(valeurInitial2 == "kg"&&valeurDesire == "lb")
valeurdouble = (valeurdouble/2.2046226);
/*System.out.println(valeurdouble);
//System.out.println(valeurPoid);
System.out.println(valeurDesire);
System.out.println(valeurInitial2);
System.out.println(valeurInitial3);*/
}
}
答案 0 :(得分:3)
如果因为它不需要另一个System.out.println()因为它不是一个循环,那么你错过了else上的{}并且它不会在最后打印任何内容。
}else if(valeurInitial2.equals( "kg" ) && valeurDesire.equals("lb" ) ){
valeurdouble = (valeurdouble/2.2046226);
System.out.println("La convertion finale : " + valeurdouble);
}