Skip to content

Instantly share code, notes, and snippets.

@Ellpeck
Last active October 10, 2019 17:51
Show Gist options
  • Save Ellpeck/999bafe352f84d5e1f09750e026d5bbf to your computer and use it in GitHub Desktop.
Save Ellpeck/999bafe352f84d5e1f09750e026d5bbf to your computer and use it in GitHub Desktop.
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