| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
runtime error,java程序贴出来了,请帮!!import java.util.Scanner;
public class Main1528 { //runtime error
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] line = in.nextLine().split("\\s");
int i = 0;
int current = 0;
StringBuffer buffer = new StringBuffer();
buffer.append("PERFECTION OUTPUT\n");
for (; i < line.length - 1; i++) {
current = Integer.parseInt(line[i]);
for (int j = 0; j < 6 - line[i].length(); j++) {
buffer.append(" ");
}
String result = compute(current);
buffer.append(current + " " + result + "\n");
}
buffer.append("END OF OUTPUT\n");
System.out.print(buffer);
}
private static String compute(int current) {
int i = 2;
int sum = 1;
if (current % 2 != 0) {
for (i = 3; i <= current/2; i += 2) {
if (current % i == 0)
sum += i;
}
} else{
for (i = 2; i <= current/2; i++) {
if (current % i == 0)
sum += i;
}
}
if (current==1) sum = 0;
if (sum < current)
return "DEFICIENT";
else if (sum > current)
return "ABUNDANT";
else
return "PERFECT";
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator