Exception handler - Printing a message And a variable in a single println Line
<p>I have a little problem that I need help with.</p>

<p>For this assignment (Lesson 12 HW9) name NumberFormatException,I had to do the following below</p>

<p>"Calculator.java, is a simple command-line calculator. Note that the program terminates if any operand is nonnumeric. Write a program with an exception handler that deals with nonnumeric operands. Your program should display a message that informs the user of the wrong operand before exiting (see the figure shown below)."</p>

<pre><code>c:\exercise&gt;java Exercise12_01 "4 + 5"

4 + 5 = 9

c:\exercise&gt;java Exercise12_01 "4 - 5"

4 - 5 = -1

c:\exercise&gt;java Exercise12_01 "4x - 5"
</code></pre>

<p>Wrong Input: 4x
SO all the math parts of the coding is finished, correct, and works, the only part I cant seem to figure out is: " display a message that informs the user of the wrong operand before exiting" Wrong Input: 4x. I need to know what I can do to show not only the error message, but the error input as well. the part where it show the error message to the user is at the end of the code at</p>

<p>Also another point i forgot to mention. the problem is that the User Might get only "N" or "V" wrong, and i dont know how to put only the Variable that is wrong while leaving the other variable alone
EX: if user put 4x - 5 (which is N - V), i just want to post 4x(N) and not 5(V) so i can show the user what the input was wrong</p>

<pre><code>catch(InputMismatchException ex)
{
    System.out.println("Bad input, please correct your operard."); 
} //need to add the input error as well
</code></pre>

<p>here the full code, thank you</p>

<pre><code>import java.util.InputMismatchException;
import java.util.Scanner;

public class NumberFormatException {

    public static void main(String[] args) 

    {
        Scanner Read = new Scanner(System.in);
        try{
//          System.out.println("What is your number?");
            System.out.println("please enter an equation");
            int n=Read.nextInt();
            char operands;
            operands=Read.next().charAt(0); //reading up till the next space and pulling the first character it read
//          System.out.println("What is your operand?");
//          operands=Read.next().charAt(0);
//      
//              
//          System.out.println("What is a second number?");
            int v=Read.nextInt();
//          System.out.println("The second number you entered was "+v);
            if (operands == '+')
                System.out.println(n+"+"+v+"="+addition(n, v));
            if (operands == '-')
                System.out.println(n+"-"+v+"="+subtraction(n, v));
            if (operands == '*')
                System.out.println(n+"*"+v+"="+multiply(n, v));
            if (operands == '/')
                System.out.println(n+"/"+v+"="+division(n, v));

        }
        catch(InputMismatchException ex)
        {
            System.out.println("Bad input, please correct your operard."); //
        }
    }


        public static int addition(int n, int v){
        return n+v;
    }
    public static int subtraction(int n, int v){
        return n-v;
    }
    public static int multiply(int n, int v){
        return n * v;
    }
    public static int division(int n, int v){
        return n/v;
    }

}
</code></pre>

<p>You can copy and post into eclipse if you want to >.&lt; thanks</p>

<hr>

<p>PS: if you think your having deja vu with this title and question, your not, I accidentally posted the wrong code at the bottom with the previous post, sorry about that guys but here the right code</p>

<p>PS2: ok the user at the bottom with his version of the code answer the question, but there another issue.   </p>

<p>there one issue im doing, is there a way to show the input as well. Im trying to show 4x as the error as well with the printout you modify but it doesnt come out </p>

<p>System.out.println("Bad input, please correct your first operand." + n); </p>

<p>I tried that just now but it want me to declare n =0 So when i did, but then : "Bad input, please correct your first operand.0" it put a zero instead of the 4x how can i fix this, a string conversion? please and thank you</p>