0% found this document useful (0 votes)
22 views2 pages

Java Program To Add Two Matrices

The document contains a Java program that implements a basic calculator using a switch statement. The program takes two integer values as input from the user, and then uses a switch statement to perform the selected arithmetic operation (+, -, *, /) on those values. It outputs the result of the operation to the user. The program handles different cases for each arithmetic operation and has default handling for invalid user input.

Uploaded by

doctor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Java Program To Add Two Matrices

The document contains a Java program that implements a basic calculator using a switch statement. The program takes two integer values as input from the user, and then uses a switch statement to perform the selected arithmetic operation (+, -, *, /) on those values. It outputs the result of the operation to the user. The program handles different cases for each arithmetic operation and has default handling for invalid user input.

Uploaded by

doctor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

www.eazynotes.com Radha Gupta, BCA 5th Sem. [2008-11 Batch], PCTE Page No.

/**** Program to Implement the Basic Functionality of a Calculator


using Switch ****/

import java.io.DataInputStream;

class Cal
{
public static void main(String args[])
{
DataInputStream pt=new DataInputStream(System.in);
int x,y,z,ch;

try
{
System.out.println("Enter Value of X:");
x = Integer.parseInt(pt.readLine());
System.out.println("Enter Value of Y:");
y = Integer.parseInt(pt.readLine());
System.out.println("1.Addition\n2.Subtraction
\n3.Multiplication\n4.Division");
System.out.println("Enter ur choice:");
ch = Integer.parseInt(pt.readLine());

switch(ch)
{
case 1:
z = x + y;
System.out.println("The Addition is:"+z);
break;
case 2:
z = x - y;
System.out.println("The Subtraction
is:"+z);
break;
www.eazynotes.com Radha Gupta, BCA 5th Sem. [2008-11 Batch], PCTE Page No. 2

case 3:
z = x * y;
System.out.println("The Multiplication
is:"+z);
break;
case 4:
z = x / y;
System.out.println("The Division is:"+z);
break;
default:
System.out.println("Sorry Try
Again.........");
break;
}
}
catch(Exception e)
{
System.out.println("x.getmessage()");
}
}
}

Output:

You might also like