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);
}}
commented: After 34 posts you should be able to use code tags. There's no excuse for not using them. -5

You need to take a third input, right? So start with that, then maybe you can figure out how to continue.

Yes thats what I'm planning to do but I do not know how to do the decision.

An if statement? Using the equals method of String?

How will I do that?Please give me even a single line of code

No. I am not going to do your homework for you. You already read lines from the user in that code and I can guarantee you've already used an if statement at somepoint in your course. You can at least make an attempt at doing your own hoemwork. Then again, I can pretty much guarantee that this isn't your code either, and so you are lost in the woods. Well, you've been given enough hints to at least be able to find the edges of those woods on your own, and you are going to have to do that before I give you anything more.

Thank You very much. Now I solved my problem. Thanks 'til next time