I have this program in which in the Switch statement structure, I've calculated an expression and want to pass its result to the stack (which I have implemented in Chars). Now the problem is that I have used
char c;
int C = 0;
switch(op)
{
case '+':
{
C = B + A;
c = (char) C;
push(c);
break;
}
case '-':
{
C = B - A;
c = (char) C;
push(c);
break;
}
case '*':
{
C = B * A;
c = (char) C;
push(c);
break;
}
case '/':
{
C = B / A;
c = (char) C;
push(c);
break;
}
}
Now if I print C (which is Integer), it would work just fine, but if I print c (which is char) or I push it to the stack, whatsoever, it would display nothing but empty. I have also used the System.out.println(C) and found out that the calculation ( C = B + A etc) works just fine but the conversion to char (c = (char) C ) does not convert the value.
Any alternative solution would be really helpful. Thanks!
System.out.println("" + ((int) c));or anything like that, that converts your char to an int first.