南昌西到昌北机场车票:Java编程高分求助!
文件名` Tmep.java:
public class Temp {
/**
* @param args void
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader keyBR = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入正数: ");
int num = Integer.parseInt(keyBR.readLine());
int total = 0;
int evenTotal = 0;
for(int i=1; i<=num; i++){//从1开始循环
total+=i;
if(i%2==0)evenTotal+=i;//偶数 (取摸2等于0的数)
}
System.out.println("1到该整数的和:" + total);
System.out.println("1到该整数的偶数和:" + evenTotal);
}
}
import java.util.*;
import java.io.*;
public class Temp {
/**
* @param args void
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader keyBR = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入正数: ");
int num = Integer.parseInt(keyBR.readLine());
int total = 0;
int evenTotal = 0;
for(int i=1; i<=num; i++){//从1开始循环
total+=i;
if(i%2==0)evenTotal+=i;//偶数 (取摸2等于0的数)
}
System.out.println("1到该整数的和:" + total);
System.out.println("1到该整数的偶数和:" + evenTotal);
}
}
楼上这位仁兄的程序是完全正确的,美中不足是缺少了包.我给加上拉.
现在可以运行拉.你试试吧.