I have variables defined outside switch and used them within switch case. I want to run a code that will take value of any switch case. This code will be outside switch. I tried but i got error like STATEMENT UNREACHABLE.
Here what i've tried :
BigDecimal firstvalue, secondvalue, calculation;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
firstvalue = new BigDecimal("45");
secondvalue = new BigDecimal("23");
switch (spinner.getSelectedItemPosition()){
case 0:
{
calculation = firstvalue.multiply(secondvalue);
break;
}
case 1:
{
calculation = firstvalue.add(secondvalue);
break;
}
case 2:
{
calculation = firstvalue.subtract(secondvalue);
break;
}
// Any of above case will apply for calculation
// Then this program that is outside switch should run
calculation.multiply(new BigDecimal("30"));
}
}
});
javafile and add the complete error message you get to your question. Also fix the indentation of your source code so it is easier to see which block starts and ends where.calculation.multiply(new BigDecimal("30"));is unreachable statement . ?????