write a program to calculate and print the sum , multiplication, division and subtraction of given to number in blueprint.. write for java..
yrr koi to bata do.. exam chal raha hai.. humble request..
correct answer will get unlimited thanks and follow
Answers
Explanation:
Java Program to Calculate the Sum, Multiplication, Division and...
public class Calculate.
Sanfoundry
Menu
Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers
« PrevNext »
This is a Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers.
Enter any two integers as input. Now choose from the given options to perform various operations on given integers.
Here is the source code of the Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
advertisement
import java.util.Scanner;
public class Calculate
{
public static void main(String[] args)
{
int m, n, opt, add, sub, mul;
double div;
Scanner s = new Scanner(System.in);
System.out.print("Enter first number:");
m = s.nextInt();
System.out.print("Enter second number:");
n = s.nextInt();
while(true)
{
System.out.println("Enter 1 for addition");
System.out.println("Enter 2 for subtraction");
System.out.println("Enter 3 for multiplication");
System.out.println("Enter 4 for division");
System.out.println("Enter 5 to Exit");
opt = s.nextInt();
switch(opt)
{
case 1:
add = m + n;
System.out.println("Result:"+add);
break;
case 2:
sub = m - n;
System.out.println("Result:"+sub);
break;
case 3:
mul = m * n;
System.out.println("Result:"+mul);
break;
case 4:
div = (double)m / n;
System.out.println("Result:"+div);
break;
case 5:
System.exit(0);
}
}
}
}
Output:
$ javac Calculate.java
$ java Calculate
Enter first number:5
Enter second number:2
Enter 1 for addition
Enter 2 for subtraction
Enter 3 for multiplication
Enter 4 for division
Enter 5 to Exit
4
Result:2.5
Enter 1 for addition
Enter 2 for subtraction
Enter 3 for multiplication
Enter 4 for division
Enter 5 to Exit
3
Result:10
Enter 1 for addition
Enter 2 for subtraction
Enter 3 for multiplication
Enter 4 for division
Enter 5 to Exit
5
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.
« Prev - Java Program to Compute List of First 100 Fibonacci Numbers
» Next - Java Program to Find if a Number is Prime or Not using Recursion
advertisement
Recommended Posts:
100+ Java Android Programming Examples
Java Programming Examples on Multithreading
Java Programming Examples on Classes
C# Programming Examples on Events
Java Programming Examples on String Handling
Java Programming Examples on Collections
Java Programming Examples on Java.Lang
Java Programming Examples
Java Programming Examples on File Handling
Java Programming Examples on Data-Structures
Java Programming Examples on Utility Classes
Java Programming Examples on Combinatorial Problems & Algorithms
Java Programming Examples on Collection API
C# Programming Examples on Matrix
C# Programming Examples on Mathematics
Simple Java Programs
Java Programming Examples on Numerical Problems & Algorithms
Java Programming Examples on Arrays
C Programming Examples on Matrix
Java Programming Examples on Mathematical Functions
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn
Subscribe Sanfoundry Newsletter and Posts
Name*
Email*
Subscribe
.
About | Certifications | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact
© 2011-2020 Sanfoundry. All Rights Reserved.
Scroll back to top
Home
Branchwise MCQs
Test & Rank
Contests
Internship
Training
Interview Preparation
C Algorithms
C++ Algorithms
Java Algorithms
Python Problems
Dynamic Programming
Data Structures MCQs
Programming Language MCQs
C Programming Examples