import java.io.*;
public class Pat
{
int a,b,c;
char ch;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
public void init()throws Exception
{
System.out.println("Enter first number:");
a=Integer.parseInt(br.readLine());
System.out.println("Enter second number:");
b=Integer.parseInt(br.readLine());
System.out.println("Enter operator (+,-,*,/):");
ch=(char)br.read();
switch(ch)
{
case '+':
add();
break;
case '-':
sub();
break;
case '*':
product();
break;
case '/':
if(b==0)
System.out.println("Division not
possible");
else
div();
break;
default:
System.out.println("Wrong
Operator");
}
}
private void add()
{
c=a+b;
System.out.println("Sum="+c);
}
private void sub()
{
c=a-b;
System.out.println("Subtracted
value="+c);
}
private void product()
{
c=a*b;
System.out.println("Product="+c);
}
private void div()
{
c=a/b;
System.out.println("Divided
result="+c);
}
public static void main(String args[])throws Exception
{
Pat ob=new Pat();
ob.init();
}
}
Sample input and output of the menu driven calculator program
Enter first number:
22
Enter second number:
33
Enter operator (+,-,*,/):
+
Sum=55
sir, please tell me the program code of the foll. pattern:
ReplyDelete12345
22345
33345
44445
55555
Already posted
ReplyDeletepublic class P
{
int i,j,n=1;
public void show()
{
for(i=0;i<5;i++)
{
n=1;
for(j=0;j<5;j++)
{
if(j<=i)
System.out.print((i+1));
else
System.out.print(n);
n++;
}
System.out.println();
}
}
public static void main(String args[]) throws Exception
{
P ob=new P();
ob.show();
}
}
sir please tell me that how i can study computer
ReplyDeleteFollow this blog and communicate with your problems through this blog site.
ReplyDeleteSir can you show the same program using AddVal(), SubVal(), MulVal(), DivVal(), ModVal() to perform addition, subtraction, multiplication, division, and modulus respectively. Please its urgent.
ReplyDeleteSimply change the function names:
Deleteimport java.io.*;
public class Pat
{
int a,b,c;
char ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void init()throws Exception
{
System.out.println("Enter first number:");
a=Integer.parseInt(br.readLine());
System.out.println("Enter second number:");
b=Integer.parseInt(br.readLine());
System.out.println("Enter operator (+,-,*,/,%):");
ch=(char)br.read();
switch(ch)
{
case '+':
AddVal();
break;
case '-':
SubVal();
break;
case '*':
MulVal();
break;
case '/':
if(b==0)
System.out.println("Division not possible");
else
DivVal();
break;
case '%':
ModVal();
break;
default:
System.out.println("Wrong Operator");
}
}
private void AddVal()
{
c=a+b;
System.out.println("Sum="+c);
}
private void SubVal()
{
c=a-b;
System.out.println("Subtracted value="+c);
}
private void MulVal()
{
c=a*b;
System.out.println("Product="+c);
}
private void DivVal()
{
c=a/b;
System.out.println("Divided result="+c);
}
private void ModVal()
{
c=a%b;
System.out.println("Remainder="+c);
}
public static void main(String args[])throws Exception
{
Pat ob=new Pat();
ob.init();
}
}
sir can u plz tell buffered reader program to identify if the entered character is upper case , lowercase ,digit or special charcter
ReplyDelete