68.2k views
1 vote
1. Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported.

User ReggieB
by
6.1k points

1 Answer

6 votes

Answer:

System.out.printf("The square root is %.4f\\",sqrt);

Step-by-step explanation:

In Java programming language using the print format method of System.out One can specify the the number of decimal places. In this case to 4 decimal places.

See a complete code snippet below

public class num1 {

public static void main(String[] args) {

double num =5;

double sqrt = Math.sqrt(5);

System.out.printf("The square root is $%.4f\\",sqrt);

}

}

User Redoff
by
6.3k points