Java 程序确定操作系统的名称和版本
javaobject oriented programmingprogramming更新于 2024/4/13 18:20:17
在本文中,我们将了解如何确定操作系统的名称和版本。这是使用 System.getProperty 函数实现的。 Java 中的 getProperty(String key) 方法用于返回通过作为其参数传递的指定键表示的系统属性。它是 java.lang.System 类的方法。
下面是相同的演示 −
输入
假设我们的输入是 −
Run the program
输出
所需的输出将是 −
系统中使用的操作系统是:Mac OS X
算法
步骤 1 - START 步骤 2 - 声明一个名为 my_os 的字符串 步骤 3 -调用函数 System.getProperty 获取操作系统的详细信息并 将其存储在字符串中 步骤 4 - 显示结果 步骤 5 - 停止
示例 1
public class OperatingSystem {
public static void main(String[] args) {
String my_os = System.getProperty("os.name");
System.out.println("The operating system being used in the system is : " +my_os);
}
}
输出
The operating system being used in the system is : Linux
示例 2
public class OperatingSystem {
public static void main(String[] args) {
String my_os = System.getProperty("os.name");
System.out.println("The operating system being used in the system is : " +my_os);
}
}
输出
The operating system being used in the system is : Linux
相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

