SlideShare une entreprise Scribd logo
1  sur  3
//Ques. 4 WAP to create equivalent of a four function calculator. The
program requires the user to enter two numbers and an operator. It
then carries out the specified arithmetic operation: addition,
subtraction,multiplication and division of two numbers.(using nested if
statement)
importjava.util.Scanner;
class calculator
{
public static void main(String arr[])
{
inta,b,c,d,e,f,g;
Scanner in = new Scanner(System.in);

System.out.println("Which Operation You wanna Perform");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division n");
c = in.nextInt();

System.out.print("nEnter First Number = ");
a = in.nextInt();
System.out.print("Enter Second Number = ");
b = in.nextInt();
if(c==1)
{
d=a+b;
System.out.println("Addition is " +d);
}
else
if(c==2)
{
e=a-b;
System.out.println("Subtraction is " +e);
}
else
if(c==3)
{
f=a*b;
System.out.println("Multiplication is " +f);
}
if(c==4)
{
g=a/b;
System.out.println("Division is " +g);
}
}
}
OUTPUT:-

Contenu connexe

Tendances

02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
Pooja Gupta
 
Simple c program
Simple c programSimple c program
Simple c program
Ravi Singh
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
moduledesign
 

Tendances (20)

C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Simple c program
Simple c programSimple c program
Simple c program
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
C # (2)
C # (2)C # (2)
C # (2)
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Function
FunctionFunction
Function
 
CIS 115 Education Specialist / snaptutorial.com
CIS 115  Education Specialist / snaptutorial.comCIS 115  Education Specialist / snaptutorial.com
CIS 115 Education Specialist / snaptutorial.com
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13
 

Similaire à programming for Calculator in java

import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
fathimafancy
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 

Similaire à programming for Calculator in java (19)

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
Java final lab
Java final labJava final lab
Java final lab
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Oot practical
Oot practicalOot practical
Oot practical
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdf
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
C#.net
C#.netC#.net
C#.net
 

Plus de One97 Communications Limited

Plus de One97 Communications Limited (20)

Er. Model Of Hospital Management
Er. Model Of Hospital ManagementEr. Model Of Hospital Management
Er. Model Of Hospital Management
 
Financial
FinancialFinancial
Financial
 
Railway
RailwayRailway
Railway
 
Library
LibraryLibrary
Library
 
Fcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt ChartFcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt Chart
 
Neural Interfacing
Neural Interfacing Neural Interfacing
Neural Interfacing
 
Blue eye technology
Blue eye technology Blue eye technology
Blue eye technology
 
Computer Forensics
Computer ForensicsComputer Forensics
Computer Forensics
 
Backtrack
BacktrackBacktrack
Backtrack
 
Protect Folders without using any Software
Protect Folders without using any SoftwareProtect Folders without using any Software
Protect Folders without using any Software
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Topology
TopologyTopology
Topology
 
WAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in javaWAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in java
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in java
 
Overriding abstract in java
Overriding abstract in javaOverriding abstract in java
Overriding abstract in java
 
How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java
 
Method overriding in java
Method overriding in javaMethod overriding in java
Method overriding in java
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in java
 
program on Function overloading in java
program on  Function overloading in javaprogram on  Function overloading in java
program on Function overloading in java
 
Program on usage of Final keyword in java
Program on usage of  Final keyword in javaProgram on usage of  Final keyword in java
Program on usage of Final keyword in java
 

Dernier

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Dernier (20)

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
The Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfThe Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdf
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 

programming for Calculator in java

  • 1. //Ques. 4 WAP to create equivalent of a four function calculator. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetic operation: addition, subtraction,multiplication and division of two numbers.(using nested if statement) importjava.util.Scanner; class calculator { public static void main(String arr[]) { inta,b,c,d,e,f,g; Scanner in = new Scanner(System.in); System.out.println("Which Operation You wanna Perform"); System.out.println("1. Addition"); System.out.println("2. Subtraction"); System.out.println("3. Multiplication"); System.out.println("4. Division n"); c = in.nextInt(); System.out.print("nEnter First Number = "); a = in.nextInt(); System.out.print("Enter Second Number = "); b = in.nextInt(); if(c==1) { d=a+b;
  • 2. System.out.println("Addition is " +d); } else if(c==2) { e=a-b; System.out.println("Subtraction is " +e); } else if(c==3) { f=a*b; System.out.println("Multiplication is " +f); } if(c==4) { g=a/b; System.out.println("Division is " +g); } } }