double num = 3.14; long roundedNum = Math.round(num); System.out.println(roundedNum); // Output: 3
double num = 6.7; int roundedNum = (int) Math.round(num); System.out.println(roundedNum); // Output: 7In this example, we have a double value 6.7 which will be rounded to the nearest integer. The rounded value will be cast to an integer and then printed on the console. Math.round() method is a part of the java.lang.Math package.