GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add pow · pythonpeixun/Java@56e8872

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Maths
    • Pow.java
    • PowRecursion.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Maths/Pow.java‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package maths;
2+
3+
public class Pow {
4+
public static void main(String[] args) {
5+
assert pow(2, 0) == Math.pow(2, 0);
6+
assert pow(0, 2) == Math.pow(0, 2);
7+
assert pow(2, 10) == Math.pow(2, 10);
8+
assert pow(10, 2) == Math.pow(10, 2);
9+
}
10+
11+
/**
12+
* Returns the value of the first argument raised to the power of the
13+
* second argument
14+
*
15+
* @param a the base.
16+
* @param b the exponent.
17+
* @return the value {@code a}<sup>{@code b}</sup>.
18+
*/
19+
public static long pow(int a, int b) {
20+
long result = 1;
21+
for (int i = 1; i <= b; i++) {
22+
result *= a;
23+
}
24+
return result;
25+
}
26+
}
Collapse file

‎Maths/PowRecursion.java‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Maths;
2+
3+
public class PowRecursion {
4+
public static void main(String[] args) {
5+
assert pow(2, 0) == Math.pow(2, 0);
6+
assert pow(0, 2) == Math.pow(0, 2);
7+
assert pow(2, 10) == Math.pow(2, 10);
8+
assert pow(10, 2) == Math.pow(10, 2);
9+
}
10+
11+
/**
12+
* Returns the value of the first argument raised to the power of the
13+
* second argument
14+
*
15+
* @param a the base.
16+
* @param b the exponent.
17+
* @return the value {@code a}<sup>{@code b}</sup>.
18+
*/
19+
public static long pow(int a, int b) {
20+
int result = 1;
21+
for (int i = 1; i <= b; i++) {
22+
result *= a;
23+
}
24+
return result;
25+
}
26+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.