.求100以內不能被3整除得數求和,如果和超過2000,跳出,打印跳出時得該數字。用java編寫。
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
int sum = 0;
for (int i = 1; i < 100; i++)
{
if (i % 3 != 0) sum += i;
if (sum > 2000) break;
}
System.out.println(sum);
}
}
運行結果 2028
在線運行通過
http://ideone.com/X4puh8
請采納,謝謝