Uploaded by karlospotify127

Java1

advertisement
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
int op,num1,num2,totala;
Scanner sc= new Scanner(System.in);
System.out.println("This is my calculator");
System.out.println("insert 1 if you want to add");
System.out.println("insert 2 if you want to subtract");
System.out.println("insert 3 if you want to multiply");
System.out.println("insert 4 if you want to divide");
op=sc.nextInt();
if(op==1){
System.out.println("insert the first number");
num1=sc.nextInt();
System.out.println("insert the second number");
num2=sc.nextInt();
totala=num1+num2;
System.out.println(num1+"+"+num2+"="+totala);
}
if(op==2){
System.out.println("insert the first number");
num1=sc.nextInt();
System.out.println("insert the second number");
num2=sc.nextInt();
totala=num1-num2;
System.out.println(num1+"-"+num2+"="+totala);
}
if(op==3){
System.out.println("insert the first number");
num1=sc.nextInt();
System.out.println("insert the second number");
num2=sc.nextInt();
totala=num1*num2;
System.out.println(num1+"*"+num2+"="+totala);
}
if(op==4){
System.out.println("insert the first number");
num1=sc.nextInt();
System.out.println("insert the second number");
num2=sc.nextInt();
totala=num1/num2;
System.out.println(num1+"/"+num2+"="+totala);
}
else{
System.out.println("enter a valid option");
}
}
}
Download