I am solving a problem which should perform addition,multiplication or subtraction on the basis of + - or * encountered in input.
Input is in the form 67+23 or 34-14 etc. So how can i check - + or * present in the input to perform the specific task.I have done so far..
import java.util.Scanner;
import java.io.IOException;
public class Summ{
public static void main(String[] args){
int a,b;
Scanner sc=new Scanner(System.in);
sc.useDelimiter("[\s+,*-]+");
a=sc.nextInt();
b=sc.nextInt();
int sum=a+b;
int diff=a-b;
int mul=a*b;
if(+ sign encountered?????){
System.out.println(" "+a);
System.out.println("+"+b);
System.out.println("_ _ _ _");
System.out.println(sum);
}
else if(- sign encountered){
System.out.println(" "+a);
System.out.println("-"+b);
System.out.println("_ _ _ _");
System.out.println(diff);
}
else if(* sign encountered){
System.out.println(" "+a);
System.out.println("*"+b);
System.out.println("_ _ _ _");
System.out.println(mul);
}
}
}