public class WhileLoopExample { public static void main(String[] args) { double n = 20; double guess = n / 2; while (guess * guess < n - 0.0001 || guess * guess > n + 0.0001) { guess = (n / guess + guess) / 2; System.out.println(guess + " squared is " + guess * guess + " and n / guess is " + n / guess); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter