Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import acm.program.ConsoleProgram;
- public class main extends ConsoleProgram {
- public void run(){
- int tall1 = readInt("Skriv inn det første tallet du vil regne med: ");
- int tall2 = readInt("Skriv inn det andre tallet du vil regne med: ");
- String oper = readLine("Skriv inn operatoren du vil de to tallene skal regne med(+,-,*,/): ");
- println(performOperation(tall1,tall2,oper));
- }
- public int performOperation(int int1,int int2,String op){
- int sum;
- if(op.equals("+")){
- sum = int1+int2;
- }
- else if(op.equals("-")){
- sum = int1-int2;
- }
- else if(op.equals("*")){
- sum = int1*int2;
- }
- else if(op.equals("/")){
- sum = int1/int2;
- }
- else{
- return 0;
- }
- return sum;
- }
- }
Add Comment
Please, Sign In to add comment