possible lossy conversion from int to short but I have no int variable

25 Views Asked by At

I was writing a code to print out the reverse of the 4-digit numbers, so my maximum number is 9999 and below 32767(maximum value of short) . The code is :

public class Project2{
    public static void main(String[] args){
        for (short i = 1000; i <= 9999; i++){
            short rev = 0;
            short temp = i;
            while (temp != 0){
                rev = rev * 10 + temp % 10;
                temp /= 10;
            }
            System.out.println(rev);
        }
    }
}

I don't know why but I'm getting compile error which mentions :possible lossy conversion from int to short and it shows 7th line for the error: rev = rev * 10 $$$+$$$ temp % 10; #error pointer is under the plus sign#

But when I convert shorts to ints it'll be ok But why am I getting an error with short?My numbers are well under the maximum value of short by the way I have no int variable to have convertion issue

0

There are 0 best solutions below