刚才测试了一下,结果如下,但结果不怎么理想。
C:\Users\lyme\Desktop>javac Test.java
注: Test.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
C:\Users\lyme\Desktop>javac Test.java
C:\Users\lyme\Desktop>java Test
x = [3,8,13,18,23,28,33,38,43,48,53,58,63,68,73,78,83,88,93,98,]
count=20
修改之后的代码如下,可以把98后面的","去掉:
public class Test {
public static void main(String[] args) {
int count = 0;
System.out.print("x = [");
for (int x = 0; x < 100; x++) {
if (x % 5 == 3) {
count++;
if(x<98)
System.out.print( x + ",");
else
System.out.print(x);
}
}
System.out.println("]");
System.out.println("count=" + count);
}
}
打印结果:
C:\Users\lyme\Desktop>javac Test.java
C:\Users\lyme\Desktop>java Test
x = [3,8,13,18,23,28,33,38,43,48,53,58,63,68,73,78,83,88,93,98]
count=20 |