题目
Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
4 28
20 152
代码块
import java.util.Scanner;//输入包
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);//输入流
while (cin.hasNext()) {
int a = cin.nextInt();
int b = cin.nextInt();
int S = 0, R = 0;
for (int i = a; i <= b; i++) {
if (i % 2 == 0)
S += (int) Math.pow(i, 2);//使用math类的函数
if (i % 2 != 0)
R += (int) Math.pow(i, 3);
}
System.out.println(S + " " + R);
}
cin.close();//关闭输入流
}
}