class realcalci
{
int ans,a,b;
char choice;
public void process(char choice,int a,int b)
{
switch(choice)
{
case '+':ans=a+b;break;
case '*':ans=a*b;break;
case '/':ans=a/b;break;
case '-':ans=a-b;break;
case '%':ans=a%b;break;
default:System.out.println("not a valid choice");
}
System.out.println("answer="+ans);
}
}
public class realcalc {
public static void main(String args[]) throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.println("enter two nos:");
int a=Integer.parseInt(br.readLine());
int b=Integer.parseInt(br.readLine());
System.out.println("+.add\n*.multiply\n/.divide\n-.subtract\n%.remainder\n");
System.out.println("enter a choice:");
char choice=(char)br.read();
realcalci obj=new realcalci();
obj.process(choice,a,b);
}
}
{
int ans,a,b;
char choice;
public void process(char choice,int a,int b)
{
switch(choice)
{
case '+':ans=a+b;break;
case '*':ans=a*b;break;
case '/':ans=a/b;break;
case '-':ans=a-b;break;
case '%':ans=a%b;break;
default:System.out.println("not a valid choice");
}
System.out.println("answer="+ans);
}
}
public class realcalc {
public static void main(String args[]) throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.println("enter two nos:");
int a=Integer.parseInt(br.readLine());
int b=Integer.parseInt(br.readLine());
System.out.println("+.add\n*.multiply\n/.divide\n-.subtract\n%.remainder\n");
System.out.println("enter a choice:");
char choice=(char)br.read();
realcalci obj=new realcalci();
obj.process(choice,a,b);
}
}
No comments:
Post a Comment