I want first to input the first number then the second number. After that input sub or add. If sub, 1st num-2nd num. If add, 1st num+second num. Then print the sum/difference. I started a code that will input 2 numbers then add. Please revise this one i can't revise it. Thank you!
import java.io.*;
public class reviewExer1 {
public static int addNum(int xVar, int yVar){
int result = 0;
result = xVar + yVar;
return result;
}
public static void main (String[]args){
int xVal = 0;
int yVal = 0;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String xinput = "0";
String yinput = "0";
System.out.print("Input x");
try {
xinput = dataIn.readLine();
}
catch (IOException e) {
System.out.println("Error!");
}
xVal = Integer.parseInt(xinput);
System.out.print("Input y:");
try {
yinput = dataIn.readLine();
}
catch (IOException e) {
System.out.println("Error!");
}
yVal = Integer.parseInt(yinput);
int resultOutput = 0;
resultOutput = addNum(xVal,yVal);
System.out.print("The sum is " + resultOutput);
}}