Skip to content

Instantly share code, notes, and snippets.

@Ellpeck

Ellpeck/Solution.java Secret

Last active Oct 10, 2019
Embed
What would you like to do?
public class Main {
public static void main(String[] args) {
int i = 27;
int exp = 3;
int j = 2500;
// initialize a counter variable that will be multiplied with i exp times
int iTo3 = 1;
// run the multiplication code exp times
for (int index = 1; index <= exp; index = index + 1) {
// for each iteration, set iTo3 to itself multiplied by i
// (because, for example, i^3 = 1 * i * i * i)
iTo3 = iTo3 * i;
}
// check if the condition is true and print accordingly
if (iTo3 <= j) {
System.out.println(i + " to the power of " + exp + " = " + iTo3 + " is less than or equal to " + j);
} else {
System.out.println(i + " to the power of " + exp + " = " + iTo3 + " is NOT less than or equal to " + j);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment