Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CalculatorMethods {
- public static void main(String[] args) {
- System.out.println(minus(10, 5)); // 5
- System.out.println(multiply(5, 5)); // 25
- System.out.println(divide(15, 3)); // 5
- }
- public static double minus(double a, double b) {
- return a + -b;
- }
- public static double multiply(double a, double b) {
- double c = 0;
- for(double i = 0; i < a; i++) {
- c += b;
- }
- return c;
- }
- public static double divide(double a, double b) {
- double c = 0;
- while(a != 0) {
- a = minus(a, b);
- c++;
- }
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment