📜  Java程序的输出| 27套(1)

📅  最后修改于: 2023-12-03 15:16:38.205000             🧑  作者: Mango

Java程序的输出 | 27套

本文介绍了27个Java程序的输出示例,涵盖了常见的输出场景和用例。

1. 输出Hello World
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

该程序输出 Hello, World!

2. 输出变量的值
public class OutputVariables {
    public static void main(String[] args) {
        int age = 27;
        double salary = 50000.50;
        String name = "John Doe";
        
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Salary: " + salary);
    }
}

该程序输出变量的值:

Name: John Doe
Age: 27
Salary: 50000.50
3. 输出数组的元素
public class OutputArrayElements {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};
        
        for (int number : numbers) {
            System.out.println(number);
        }
    }
}

该程序输出数组 numbers 中的元素:

1
2
3
4
5
4. 输出多个变量的值
public class OutputMultipleVariables {
    public static void main(String[] args) {
        int x = 10, y = 20, z = 30;
        
        System.out.println("x = " + x + ", y = " + y + ", z = " + z);
    }
}

该程序输出多个变量的值:

x = 10, y = 20, z = 30
5. 输出条件判断结果
public class ConditionalOutput {
    public static void main(String[] args) {
        int number = 15;
        
        if (number % 2 == 0) {
            System.out.println(number + " is even.");
        } else {
            System.out.println(number + " is odd.");
        }
    }
}

该程序根据条件判断结果输出:

15 is odd.

以上是5个Java程序的输出示例,接下来的部分将继续介绍其他示例。

...

请继续丰富内容,添加更多Java程序的输出示例。