import javax.measure.Quantity; import javax.measure.quantity.Length; import javax.measure.unit.SI; import javax.measure.unit.Unit; public class MeasurementExample { public static void main(String[] args) { Quantity<Length> length = Quantity.of(10, SI.METER); double value = length.getValue(); Unit<Length> unit = length.getUnit(); System.out.println("Length: " + value + " " + unit); Quantity<Length> convertedLength = length.to(SI.CENTIMETER); System.out.println("Converted Length: " + convertedLength.getValue() + " " + convertedLength.getUnit()); Quantity<Length> addedLength = length.add(convertedLength); System.out.println("Added Length: " + addedLength.getValue() + " " + addedLength.getUnit()); } } <project> <dependencies> <dependency> <groupId>org.unitsofmeasurement</groupId> <artifactId>unit-api</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.unitsofmeasurement</groupId> <artifactId>unit-impl</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.unitsofmeasurement</groupId> <artifactId>unit-ri</artifactId> <version>1.0</version> </dependency> </dependencies> </project>


上一篇:
下一篇:
切换中文