Guest User

Untitled

a guest
May 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import acm.program.ConsoleProgram;
  2.  
  3.  
  4. public class main extends ConsoleProgram {
  5.  
  6.     public void run(){
  7.         int tall1 = readInt("Skriv inn det første tallet du vil regne med: ");
  8.         int tall2 = readInt("Skriv inn det andre tallet du vil regne med: ");
  9.         String oper = readLine("Skriv inn operatoren du vil de to tallene skal regne med(+,-,*,/): ");
  10.         println(performOperation(tall1,tall2,oper));
  11.     }
  12.     public int performOperation(int int1,int int2,String op){
  13.         int sum;
  14.         if(op.equals("+")){
  15.             sum = int1+int2;
  16.         }
  17.         else if(op.equals("-")){
  18.             sum = int1-int2;
  19.         }
  20.         else if(op.equals("*")){
  21.             sum = int1*int2;
  22.         }
  23.         else if(op.equals("/")){
  24.             sum = int1/int2;
  25.         }
  26.         else{
  27.             return 0;
  28.         }
  29.         return sum;
  30.         }
  31.     }
Add Comment
Please, Sign In to add comment