thorax232

Java - Calculator Methods

Nov 7th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. public class CalculatorMethods {
  2.     public static void main(String[] args) {
  3.         System.out.println(minus(10, 5)); // 5
  4.         System.out.println(multiply(5, 5)); // 25
  5.         System.out.println(divide(15, 3)); // 5
  6.     }
  7.    
  8.     public static double minus(double a, double b) {
  9.         return a + -b;
  10.     }
  11.    
  12.     public static double multiply(double a, double b) {
  13.         double c = 0;
  14.         for(double i = 0; i < a; i++) {
  15.             c += b;
  16.         }
  17.        
  18.         return c;
  19.     }
  20.    
  21.     public static double divide(double a, double b) {
  22.         double c = 0;
  23.         while(a != 0) {
  24.             a = minus(a, b);
  25.             c++;
  26.         }
  27.        
  28.         return c;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment