class OperatorExample{
public static void main(String args[])
{
short a=10;
short b=10;
//a+=b;//a=a+b internally so fine
//a=a+b;//Compile time error because 10+10=20 now int
a=(short)(a+b);//20 which is int now converted to short
System.out.println(a);
}
}
20
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.