编写函数,计算2个整数的平方和,并将结果返回,在主函数中调用该函数,并输出结果。jAVA
时间: 2024-03-16 12:44:14 浏览: 53
C语言编程-编写函数fun求1!+2!+3!+ …… +n!的和,在main函数中由键盘输入n值,并输出运算结果;
5星 · 资源好评率100%
以下是Java代码:
```
public class Main {
public static void main(String[] args) {
int num1 = 3;
int num2 = 4;
int sumOfSquares = calculateSumOfSquares(num1, num2);
System.out.println("The sum of squares of " + num1 + " and " + num2 + " is " + sumOfSquares);
}
public static int calculateSumOfSquares(int num1, int num2) {
int square1 = num1 * num1;
int square2 = num2 * num2;
int sumOfSquares = square1 + square2;
return sumOfSquares;
}
}
```
输出结果为:
```
The sum of squares of 3 and 4 is 25
```
阅读全文