-
-
Save Ellpeck/999bafe352f84d5e1f09750e026d5bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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