kocev

XandY

Feb 19th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class XAndY {
  2.     public static void main(String[] args) {
  3.  
  4.         final int X = 5;
  5.         final int Y = 6;
  6.         System.out.printf("X * Y = %d%n", Multiplication(X, Y));
  7.         System.out.printf("X ^ Y = %d%n", Power(X, Y));
  8.     }
  9.  
  10.     public static int Multiplication(int a, int b) {
  11.         int result = 0;
  12.         for (int i = 0; i < b; i++) {
  13.             result += a;
  14.         }
  15.  
  16.         return result;
  17.  
  18.     }
  19.  
  20.     public static int Power(int a, int b) {
  21.         int result = 1;
  22.         int i = 0;
  23.         while (i < b) {
  24.             i++;
  25.             result *= a;
  26.         }
  27.         return result;
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment