2番目のケースでコンパイルエラーが発生し、5が文字列で4がintであることが示されます。これは最初のケースでも同じですが、出力が得られます。2番目のケースで文字列の連結が許可されないのはなぜですか?
class Test
{
public static void main(String args[])
{
System.out.println("The sum is: "+5*4); //Gives output The sum is: 20
System.out.println("The sum is: "+5-4);
//Gives compilation error shows 5 is string while 4 is int.This should be the case with prevous case also but it gives output.Why????
}
}
[演算子の優先順位](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) –
あなたが5-4をinside()に入れればうまくいくでしょう。これは優先順位のために起こっています。 –