1. 求从10到100中能被3或5整除的数的和
int sum = 0;
for(int i = 10; i <= 100; i++) if( i % 3 == 0 || i % 5 == 0) sum += i;
System.out.println(sum);
2. 将一个字符串逆序,不要使用反转函数
String message = "he saw a racecar";
StringBuilder rev = new StringBuilder();
for(int i = message.length()-1; i >= 0; i--) rev.append(message.charAt(i));
System.out.println(rev.toString());
|
|