なぜ条件が満たされていない場合に戻り値-1
を取得できないのですか?なぜ条件が満たされていないときに-1の戻り値を取得できないのですか?
package calcfeetandinchestocm;
public class Calcfeetandinchestocm {
public static void main(String[] args) {
calcFeetAndInchesToCentimeters(4, 12);
calcFeetAndInchesToCentimeters(-0.5);
}
public static int calcFeetAndInchesToCentimeters(double feet, double inches) {
if (feet >= 0) {
System.out.println("feet are " + feet + \
" and its equal centimeters are " + feet * 12);
}
if (inches >= 0 && inches <= 12) {
System.out.println("inches are " + inches + \
"and its equal centimeters are " + inches * 2.45);
}
return -1;
}
public static int calcFeetAndInchesToCentimeters(double inches) {
if (inches >= 0) {
System.out.println("inches are " + inches + \
"and its equal centimeters are " + inches * 2.45);
}
return -1;
}
}
あなたは戻り値を無視しているので、どのようにあなたが取得されていません知っています-1? – John3136
戻り値は決してチェックしていません。入力が悪いときにどのような振る舞いをしたいですか?ところで、1フィートは12センチメートルに等しくありません:-) –
はい!それは間違っている。これは12フィートと等しい1フィートになることを意味していた –