Posted by: khai_k_khai_k October 6, 2008
Login in to Rate this Post:
0
?
/* Use System.out.format to maintain the precision of the double value */
/* Try to read books like Core Java Vol 1, if u are a beginner. */
public class SquareRoot {
public static void main(String[] args) {
System.out.println("Number \t SquareRoot");
for (int i = 0; i <= 20; i = i + 2) {
System.out.format("%d \t %1.4f \n", i, Math.sqrt(i));
}
}
}
/* Output */
/*
Number SquareRoot
0 0.0000
2 1.4142
4 2.0000
6 2.4495
8 2.8284
10 3.1623
12 3.4641
14 3.7417
16 4.0000
18 4.2426
20 4.4721
*/
/* Try to read books like Core Java Vol 1, if u are a beginner. */
public class SquareRoot {
public static void main(String[] args) {
System.out.println("Number \t SquareRoot");
for (int i = 0; i <= 20; i = i + 2) {
System.out.format("%d \t %1.4f \n", i, Math.sqrt(i));
}
}
}
/* Output */
/*
Number SquareRoot
0 0.0000
2 1.4142
4 2.0000
6 2.4495
8 2.8284
10 3.1623
12 3.4641
14 3.7417
16 4.0000
18 4.2426
20 4.4721
*/