Created
June 27, 2018 13:13
-
-
Save Techgokul/0a965aab8372ca4265afb4b6d24b9ae9 to your computer and use it in GitHub Desktop.
Create java application of 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 SimpleCalculator { | |
public static void mainM(String[] args) { | |
Scanner input=new Scanner(System.in); | |
int fnum,snum,ans; | |
char sign; | |
System.out.println("Welcome User,This is a Simple Calculator Created by Victor Using the if statement"); | |
System.out.print("Please Enter your first digit: "); | |
fnum=input.nextInt(); | |
System.out.print("Enter the second digit: "); | |
snum=input.nextInt(); | |
System.out.print("Enter the mathematical operator to be used: "); | |
sign=input.next().charAt(0); | |
ans=fnum + snum; | |
System.out.println(fnum +" "+sign +" "+snum +"= "+" "+ ans ); | |
} | |
else if(sign == '-')/* else if statement for minus sign*/ | |
{ | |
ans=fnum-snum; | |
System.out.println(fnum +" "+sign +" "+snum +"= "+" "+ ans ); | |
} | |
else if(sign == '/'){ | |
ans=fnum/snum; | |
System.out.println(fnum +" "+sign +" "+snum +"= "+" "+ ans ); | |
} | |
else if(sign == '*'){ | |
ans=fnum*snum; | |
System.out.println(fnum +" "+sign +" "+snum +"= "+" "+ ans ); | |
} | |
else | |
System.out.println("Your Input is not correct,please check it for any error(s)."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment