The typecasting of data types works here, as we need end results in BYTE format.
The correct code is:
public class Exchange
{
public static void main(String[] args)
{
byte a = 23, b = 44;
a = (byte) (a + b);
b = (byte) (a - b);
a = (byte) (a - b);
System.out.println("a="+a, "b="+b);
}
}