Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class XAndY {
- public static void main(String[] args) {
- final int X = 5;
- final int Y = 6;
- System.out.printf("X * Y = %d%n", Multiplication(X, Y));
- System.out.printf("X ^ Y = %d%n", Power(X, Y));
- }
- public static int Multiplication(int a, int b) {
- int result = 0;
- for (int i = 0; i < b; i++) {
- result += a;
- }
- return result;
- }
- public static int Power(int a, int b) {
- int result = 1;
- int i = 0;
- while (i < b) {
- i++;
- result *= a;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment