I recently made a program to be a calculator but three errors occurred. Here is the code:
import java.util.Scanner;
public class mathyStuff {
public static void main(String[] args) throws InterruptedException {
Scanner raw = new Scanner(System.in);
String input = raw.nextLine();
int y = 0;
while (y < input.length()) {
if (input.substring(y, y+1) == "+" || input.
substring(y, y+1) == "-" || input.substring(y, y+1) == "/" || input.substring(y, y+1) == "*") {
String x = input.substring(y, y+1);
int z1 = Integer.parseInt(input.substring(0,y));
int z2 = Integer.parseInt(input.substring(y+1, 0));
}
else {
y = y + 1;
}
}
math(z1,x,z2);
}
public static void math (int num1, String op, int num2) throws InterruptedException {
if (op == "+") {
System.out.println(String.valueOf(num1 + num2));
}
if (op == "-") {
System.out.println(String.valueOf(num1 - num2));
}
if (op == "*") {
System.out.println(String.valueOf(num1 * num2));
}
if (op == "/") {
System.out.println(String.valueOf(num1 / num2));
}
}
}
Here is the errors:
Compilation Errors Detected
Line: 18
cannot find symbol
symbol: variable z1
location: class mathyStuff
Line: 18
cannot find symbol
symbol: variable x
location: class mathyStuff
Line: 18
cannot find symbol
symbol: variable z2
location: class mathyStuff
I'm currently using a website called browxy, an online java compiler. And yes, I know. Download eclipse. I can't bring my computer everywhere I go so I use this instead.