Sample input:
112233
30800
2937
323455693
5038297
112234
0
Sample output
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.
大意:
給1個1000位以下的數字 求可否被11整除
import java.util.Scanner;
public class UVA10929 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
String N = sc.next();
if (N.equals("0"))
break;
long sum = 0;
for (int i = 1; i <= N.length(); i++) {
if (i % 2 != 0) {
sum += Integer.parseInt(N.substring(i - 1, i));
} else if (i % 2 == 0) {
sum -= Integer.parseInt(N.substring(i - 1, i));
}
}
if (sum % 11 == 0)
System.out.println(N + " is a multiple of 11.");
else
System.out.println(N + " is not a multiple of 11.");
}
}
}