Here is a calculator program I had to make in my Computer class in bluej (free java compiler)
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.");
}
}
}
// Program for simple calculator
public class Calc
{
public static void main(String args[])
{
int x,w,z;
char y;
if(args[]!=3)
{
System.out.println("Wrong Syntax");
System.out.println("NOTE: Please compile like this");
System.out.println("c:\java\jdk1.6\javac Calc 25 + 3 ");
System.out.println("c:\java\jdk1.6\javac Calc 25 - 3 ");
System.out.println("c:\java\jdk1.6\javac Calc 25 x 3 ");
System.out.println("c:\java\jdk1.6\javac Calc 25 / 3 ");
System.out.println("c:\java\jdk1.6\javac Calc 25 % 3 ");
System.exit(0);
}
x= Integer.parseInt(args[0]);
y= Character.parseChar(args[1]);
z= Integer.parseInt(args[2]);
switch(y)
{
case '+' : w=x+z;
System.out.println("Addition = "+w);
break;
case '-' : w=x-z;
System.out.println("Substraction = "+w);
break;
case 'x' :
case 'X' : w=x*z;
System.out.println("Multiplication = "+w);
break;
case '/' : w=x/z;
System.out.println("Division = "+w);
break;
case '%' : w=x%z;
System.out.println("Modulus = "+w);
break;
}
}
}
You can use the built-in methods of the java Math class to do the actual calculations. If you are supposed to do this yourself, rather than using available components, you can use the infinite series expansion (Taylor series) which you can find online in many places. For example:
sin(x) = x - x3/3! + x5/5! - x7/7! + x9/9! ...
Although in theory the series is infinite, in practice you'll continue adding terms until the current term becomes less than some threshold value, depending on the desired accuracy. Or rather, the absolute value of the term.
5!, for example, means 5!, in other words, 1 x 2 x 3 x 4 x 5. Note that the angle must be in radians. If the angle is in degrees, you must convert to radians first. This applies to the built-in methods of the Math class as well.
The Wikipedia article "Taylor series" contains the infinite series for other trigonometric functions. Some of these are too complicated, in my opinion; for example, to calculate tan(x), it is more convenient to use the identity tan(x) = sin(x) / cos(x), and re-use the sin() and cos() methods instead. Also, sec(x) = 1 / cos(x), csc(x) = 1 / sin(x), and cot(x) = 1 / tan(x).
The command to compile a Java program is "javac", followed by the class name (file name).
In the same way as you would compile and execute any other Java program. Compile: use the "javac" command. Or use the built-in "compile" command in your favorite IDE. Execute: Use the "java" command. Or use the built-in "run" command in your favorite IDE.
Hello Frnd, As u say u want to Compile & Run Java Prog. for This if U have JAVA CREATOR then u can compile directly otherwise........ goto Start >run type "cmd" Press "Enter"after that goto C>java>bin> type for compile the prog. "javac PROG.NAME.java" Press "Enter" if Compile SuccessFully Type "java PROG.NAME" Press "Enter" For It This Is Must u save ur Prog. in the folder "bin" in java............. Hello Frnd, As u say u want to Compile & Run Java Prog. for This if U have JAVA CREATOR then u can compile directly otherwise........ goto Start >run type "cmd" Press "Enter"after that goto C>java>bin> type for compile the prog. "javac PROG.NAME.java" Press "Enter" if Compile SuccessFully Type "java PROG.NAME" Press "Enter" For It This Is Must u save ur Prog. in the folder "bin" in java.............
You use javac <filename> to compile a class or package.
Java Integrated Development Environment (IDE) provides an environment to Edit, compile and debug and generate java codeThere are several java IDE like Eclipse, WSAD, BlueJ, JCreator etc
You compile it.You compile it.You compile it.You compile it.
One can run and compile a Java applet program by agreeing to the terms and downloading it. It is possible to get a compiler online that will compile and run Java programs.
The command to compile a Java program is "javac", followed by the class name (file name).
How can I compile java programs using windows vista text pad?
Tomcat is a server. It is used to deploy and run Servlets and not compile them. A Servlet is a java file and has to be compiled just like any other Java Class.
In the same way as you would compile and execute any other Java program. Compile: use the "javac" command. Or use the built-in "compile" command in your favorite IDE. Execute: Use the "java" command. Or use the built-in "run" command in your favorite IDE.
HelloWorld.classrun it with command java HelloWorld
It should work, yes. It really doesn't matter where you compile it - if you compile under Windows XP, you don't compile FOR Windows XP; rather, you compile for the virtual machine, which is compatible in different environments.
Hello Frnd, As u say u want to Compile & Run Java Prog. for This if U have JAVA CREATOR then u can compile directly otherwise........ goto Start >run type "cmd" Press "Enter"after that goto C>java>bin> type for compile the prog. "javac PROG.NAME.java" Press "Enter" if Compile SuccessFully Type "java PROG.NAME" Press "Enter" For It This Is Must u save ur Prog. in the folder "bin" in java............. Hello Frnd, As u say u want to Compile & Run Java Prog. for This if U have JAVA CREATOR then u can compile directly otherwise........ goto Start >run type "cmd" Press "Enter"after that goto C>java>bin> type for compile the prog. "javac PROG.NAME.java" Press "Enter" if Compile SuccessFully Type "java PROG.NAME" Press "Enter" For It This Is Must u save ur Prog. in the folder "bin" in java.............
to compile and run java program you need to set path and classpath path refers to binary used to compile and run java program i.e. "javac" for compilation and "java" for execution
javac is the command that is used to compile Java source files.
by adding more documents