What happened to my code? The following code worked for integer type of data, but couldn\'t work for byte type of data.
public class Exchange {
public st
Simply, Cast the result of your arithmetic operation to byte as follows:
public class Exchange {
public static void main(String[] args) {
//int a = 23, b = 44;
byte a = 23, b = 44;
a = (byte) a + b;
b = (byte) a - b;
a = (byte) a - b;
System.out.println("a=" + a + "b=" + b);
}
}
Tip:- Use Alt+Enter for hints