Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

写一段关于java的代码

  1. User

    写一段关于java的代码

  2. Assistant

    Sure! Here's an example of a simple Java code to calculate the sum of two numbers:

    public class SumCalculator {
        public static void main(String[] args) {
            int num1 = 5;
            int num2 = 10;
            int sum = num1 + num2;
            System.out.println("The sum of " + num1 + " and " + num2 + " is: " + sum);
        }
    }
    

    In this code, we define a class named "SumCalculator" and a method called "main". Inside the main method, we declare two integer variables num1 and num2 and assign them the values 5 and 10 respectively.

    We then create a new variable called sum to store the result of adding num1 and num2 together.

    Finally, we use the System.out.println() method to print the sum on the console.