Last active
August 29, 2015 14:08
-
-
Save mralext20/189fdd85949740a84c11 to your computer and use it in GitHub Desktop.
java based calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Calculator { | |
public static void main(String[] args) { | |
int type; | |
double first, secound, answer; | |
Scanner scan = new Scanner(System.in); | |
System.out.println("hello! what kind of math would you like to do today?"); | |
System.out.println("[1]: addition"); | |
System.out.println("[2]: subtraction"); | |
System.out.println("[3]: multiplacation"); | |
System.out.println("[4]: division"); | |
type = scan.nextInt(); | |
if(type == 1){ | |
System.out.println("enter first number:"); | |
first = scan.nextDouble(); | |
System.out.println("enter secound number"); | |
secound = scan.nextDouble(); | |
answer= first + secound; | |
System.out.println(first +" plus "+ secound + " is "+answer ); | |
}; | |
if (type == 2){ | |
System.out.println("enter first number"); | |
first = scan.nextDouble(); | |
System.out.println("enter secound number"); | |
secound = scan.nextDouble(); | |
answer= first - secound; | |
System.out.println(first +" minus "+ secound+" is "+answer); | |
} | |
if (type == 3) { | |
System.out.println("enter first number"); | |
first = scan.nextDouble(); | |
System.out.println("enter secound number"); | |
secound = scan.nextDouble(); | |
answer=first*secound; | |
System.out.println(first + " multiplied by "+secound+" is "+answer); | |
} | |
if (type == 4) { | |
System.out.println("enter first number"); | |
first = scan.nextDouble(); | |
System.out.println("enter secound number"); | |
secound = scan.nextDouble(); | |
answer=first/secound; | |
System.out.println(first+" divided by "+secound+" is "+answer); | |
} | |
if (type>4) { | |
System.out.println("i dont understand you. please try again."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment