gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
写一段关于java的代码
- User
写一段关于java的代码
- 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
num1andnum2and assign them the values 5 and 10 respectively.We then create a new variable called
sumto store the result of addingnum1andnum2together.Finally, we use the
System.out.println()method to print the sum on the console.