Thanks for having a look at my question. I wanna ask that can i take character or arithmetic operator as input from the user without using scanner?
This is my code to Write a program using the arithmetic operators to perform algebraic operations on two numbers. (Algebraic operation is +, - , *, /, %)
import java.util.Scanner;
class q4
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in );
int a, b;
char operator;
System.out.print("Enter A : ");
a=s.nextInt();
System.out.print("Enter B : ");
b=s.nextInt();
System.out.print("Enter operator (+, -, *, /)");
operator = s.next().charAt(0);
double addition = a+b;
double subtraction = a-b;
double multiplication = a*b;
double division = a/b;
switch(operator)
{
case '+' :
{
System.out.print("Total after Addition is : "+addition);
break;
}
case '-' :
{
System.out.print("Total after Subtraction is : " +subtraction);
break;
}
case '*' :
{
System.out.print("Total after Multiplication is : "+multiplication);
break;
}
case '/' :
{
System.out.print("Total after Division is : "+division);
break;
}
default :
{
System.out.print("Please select proper operator");
return;
}
}
}
}
Thanks for replying me even when you are very busy :)