是否可以将数字舍入到最接近的几个预定数字?
它可能看起来像
import java.util.ArrayList;
import java.util.List;
class Company {
private String name;
private List<String> empList = new ArrayList<>();
public Company(String name, List<String> empList) {
this.name = name;
this.empList = empList;
}
public String getName() {
return name;
}
public List<String> getEmpList() {
return empList;
}
public Object copy() {
List<String> tempList = new ArrayList<>();
for (String s : this.empList) {
tempList.add(s);
}
String cName = this.name;
return new Company(cName, tempList);
}
}
public class TestDeepClone {
public static void main(String[] args) {
List<String> empList = new ArrayList<>();
empList.add("Bibhu");
empList.add("Raj");
empList.add("John");
Company c1 = new Company("ABC Company", empList);
Company c2 = (Company) c1.copy();
System.out.println(c1.getClass() == c2.getClass());//true
System.out.println(c1.getEmpList() == c2.getEmpList());//false
}
}
,它将x舍入到最接近的指定数字。
所以你会得到:
round(x,3,6,13)
x = 4
round(x,3,6,13) = 3
x = 7
round(x,3,6,13) = 6
x = 10