Another option is to simply declare variables a & b in the global context. 
Which in Java terms they’d be known as fields. 
int a, b;
void example(final char ch) {
if (ch == 'y') {
a *= b;
b = (a + 5) * (b - 2);
} else {
b /= a;
a += b;
}
}