用Java显示操作系统名称
使用Java中的System.getProperty()方法获取操作系统名称。
它的语法是-
String getProperty(String key)
在上方,键是系统属性的名称。由于我们需要操作系统名称,因此我们将键添加为-
os.name
示例
public class Demo {
public static void main(String[] args) {
System.out.print("Operating System: ");
System.out.println(System.getProperty("os.name"));
}
}输出结果
Operating System: Linux