answersLogoWhite

0


Best Answer

import java.io.*;

import java.util.*;

public class Calculator

{

public static void main(String args[])

{

System.out.println("Make your arithmetic selection from the choices below:\n");

System.out.println(" 1. Addition");

System.out.println(" 2. Subtraction");

System.out.println(" 3. Multiplication");

System.out.println(" 4. Division\n");

System.out.print(" Your choice? ");

Scanner kbReader = new Scanner(System.in);

int choice = kbReader.nextInt();

if((choice<=4) && (choice>0))

{

System.out.print("\nEnter first operand. ");

double op1 = kbReader.nextDouble();

System.out.print("\nEnter second operand.");

double op2 = kbReader.nextDouble();

System.out.println("");

switch (choice)

{

case 1: //addition

System.out.println(op1 + " plus " + op2 + " = " + (op1 + op2) );

break;

case 2: //subtraction

System.out.println(op1 + " minus " + op2 + " = " + (op1 - op2) );

break;

case 3: //multiplication

System.out.println(op1 + " times " + op2 + " = " + (op1 * op2) );

break;

case 4: //division

System.out.println(op1 + " divided by " + op2 + " = " + (op1 / op2) );

}

}

else

{

System.out.println("Please enter a 1, 2, 3, or 4.");

}

}

}

User Avatar

Wiki User

βˆ™ 14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A complete java code to make calculator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is java file in java?

A java file contains the code you write. One java file contains one class so for example when I want to make a class called Person, the source code is saved in Person.java


How do you make a RuneScape calculator?

First of all, you need some experience in computer programming - for example, Java or Flash.


How do people make minecraft mods?

They program them using code and Java.


How do you make menu using jcreator in java?

Currency Source Code Using JCreator


How do you create a simple decipher code in java?

decipher code depends upon the algorithm you used to make them. there are no general methods.


How does VM code compiler works?

The Java virtual machine is not a compiler, it is an interpreter which primarily performs runtime-translation of Java byte code (the native language of the Java virtual machine) to machine-code (the native language of the physical machine). The Java compiler, on the other hand, is a separate program used to perform compile-time conversion of high-level Java source code to the lower level byte code. Java byte code is highly portable; once compiled, any architecture or platform that implements a JVM can execute the byte code without modification.


How do you make a java class?

You write the source code, in a text editor, or better in a special IDE. The source code should have the extension ".java". You can have several classes in the same file. Then you compile the class to bytecode; this creates a file with extension ".class".


Why java interpreted?

Java is both compiled and interpreted. At first, the Java source code (in .java files) is compiled into the so-called Bytecode (.class files). The Bytecode is a pre-compiled, platform independent version of your program. The .class files can be used on any operating system. When the Java application is started, the Bytecode is interpreted by the Java Virtual Mashine. Because the Bytecode is pre-compiled, Java does not have the disadvantages of classical interpreted languages, like BASIC.


What is a function in java?

The term equivalent to functions in Java is "methods". Methods are pieces of code that are used to make some functionality. Ex: public String getName(){ return "Anand"; } The above is a sample method


I have a computer science class and I need to make a java file that executes with conditional operations and iterative operations. How do you make a java file with conditional and iterative?

This is what you need in your class code. 1. Main Method - So that you can execute it 2. If - else block - Where you have conditions 3. For or while loop - Where there is iterative code Note: I can write the code here but wiki is not the place to get your homework done.


What is the input and output to a Java interpreter?

The input is source code (MyClass.java) and the output is bytecode (MyClass.class).Generally, Java compilers receive as input .java source code files, and output .class binary files which are then executed by the Java Virtual Machine (JVM) executable.Some Java compilers output binaries in machine code that can be directly executed.The input is a source file with the java extension. (i.e. HelloWorld.java) The output is the byte code file with the class extension. (i.e. HelloWorld.class)Input:1. Most compilers take as input the source program which is in a particular programming language.2. Compilation Switches ( special arguments that tell the nature of compilation and structure of target code).3. Supporting Files (Library Files) such files help in the execution and translation of a programOutput:1. Program List file.2. Target Code. Target code is the equivalent of the source code but in another language


What do you get when you compile a java program?

The java interpreter or JVM (Java Virtual Machine) is not able to execute the java source code for a program. The java source code first needs to be compiled into bytecode that can be processed by JVM. Producing bytecode make the program platform independent as each platform has its own JVM. It is also possible to directly write bytecode, bypassing the need to compile, but that would be tedious job and also not good for security purpose as the compiler checks for various errors in a program.