import java.io.*;
public class SortCount {
static InputStreamReader in;
static BufferedReader reader;
static {
in = new InputStreamReader(System.in);
reader = new BufferedReader(in);
}
// 读取整数
public static int readInt() {
int i = 0;
try {
String s1 = reader.readLine();
i = Integer.parseInt(s1);
} catch (Exception e) {
System.exit( 0 );
}
return i;
}
// 冒泡排序
public static void sort(int[] num) {
int mid;
int i, j;
for (i = 0; i < 10; i++)
for (j = i + 1; j < 10; j++)
if (num[i] > num[j]) {
mid = num[i];
num[i] = num[j];
num[j] = mid;
}
}
// 正数求和
public static int total(int[] num) {
int result = 0;
for (int i = 0; i < num.length; i++) {
if (num[i]>0)
result = result + num[i];
}
return result;
}
public static void main(String args[]) {
int a[] = new int[10];
for (int i = 0; i < 10; i++) {
System.out.println("请输入第" + (i + 1) + "个数:");
a[i] = SortCount.readInt();
}
// 排序
sort(a);
// 求和
int result = total(a);
System.out.println(result);
}
}
0
顶
0
踩
分享到:
2009-10-09 15:08
浏览 3066
评论