switch statement not working for JFrame Calculator
I am working on a calculator for my Java programming class. I have the whole interface with buttons set up but right now I'm having a problem with my case statements.
This is what my case statement says for my equals button.
Quote:
switch ( math_operator ) {
case '+':
total2 = total1 + Double.parseDouble(textDisplay.getText( ) );
break;
case '-':
total2 = total1 - Double.parseDouble(textDisplay.getText( ) );
break;
case '/':
total2 = total1 / Double.parseDouble(textDisplay.getText( ) );
break;
case '*':
total2 = total1 * Double.parseDouble(textDisplay.getText( ) );
break;
case '1/x': //MY ERROR IS RIGHT HERE.
total2=1/total1;
break;
case '√':
total2 = Math.pow(total1,.5);
break;
case '%':
total2 = total1/100;
case '2':
total2 = Math.pow(total1,2);
textDisplay.setText(Double.toString(total2));
total1=0;}
When I try to type something in that is longer then 1 bit it gives me an error. (unclosed character literal). For all the other functions its only 1 bit so far and that is the text on my button for my interface. If you could please help!!
Re: switch statement not working for JFrame Calculator