Skip to content

Instantly share code, notes, and snippets.

@joeyv
Last active December 26, 2015 11:39
Show Gist options
  • Save joeyv/7145566 to your computer and use it in GitHub Desktop.
Save joeyv/7145566 to your computer and use it in GitHub Desktop.
Displays the square roots of 25 and every number 5 less than it until you reach 0. Using a while loop and for loop
public class Root {
public static void main(String[] args)
{
int base = 25;
while(base > 0){
System.out.println("Square root of " + base + "\t= " + Math.sqrt(base));
base -= 5;
}
}
}
public class Root2 {
public static void main(String[] args)
{
int base = 25;
for (base = 25; base > 0; base -= 5){
System.out.println("Square root of " + base + "\t= " + Math.sqrt(base));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment