Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 26, 2015 09:18
Show Gist options
  • Save imryan/7127933 to your computer and use it in GitHub Desktop.
Save imryan/7127933 to your computer and use it in GitHub Desktop.
Calculates square root of 25 and 5 less until 0 is reached.
public class Root {
public static void main(String[] args)
{
// Declare base as an integer with a value of 30
int base = 30;
while (base != 0) {
// Decrease base by -5
base -= 5;
// Output square root of each new base
System.out.println("Square root of: " + base + "\t=\t" + Math.sqrt(base));
}
}
}
public class Root2 {
public static void main(String[] args)
{
// Declare base as an integer with a value of 25
int base = 25;
// Loop base as -5 each time
for (base = 25; base > 0; base -= 5)
{
// Output square root of each new base
System.out.println("Square root of: " + base + "\t=\t" + Math.sqrt(base));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment