Wednesday, January 25, 2012

arithmetic operators


//arthemetic operators using switch
import java.io.*;
class Input2
{
public static void main(String[] args)throws IOException
{
char ch;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("enter values of x");
int x=Integer.parseInt(br.readLine());
System.out.println("enter values of y");
int y=Integer.parseInt(br.readLine());
System.out.println("enter u r choice");
System.out.println("+ for additon");
System.out.println("- for subtraction");
System.out.println("/ for divide");
System.out.println("* for multipiy");
System.out.println("% for remainder");
ch=(char)br.read();
switch(ch)
{
case '+':
System.out.println("additon:"+(x+y));
break;
case '-':
System.out.println("sub:"+(x-y));
break;
case '*':
System.out.println("mul:"+(x*y));
break;
case '/':
System.out.println("divide:"+(x/y));
break;
case '%':
System.out.println("Remainder:"+(x%y));
break;
}
}
}