请大家帮我看下,不知道怎么回事,用第二个FOR语句的时候就读不出值来,读出来全是零
public static void main(String[] args) throws IOException {
int a[]=new int[100];
int i;
for( i=0;i<100;i++){
if((i+1)%3==0&&(i+1)%7==0){
a[i]=i+1;
}
}
for(i=a.length-1;i>=0;i--)
System.out.println(a[i]);
}
public static void main(String[] args) throws IOException {
int a[]=new int[100];
int i;
for( i=0;i<100;i++){
if((i+1)%3==0&&(i+1)%7==0){
a[i]=i+1;
}
}
for(i=a.length-1;i>=0;i--)
System.out.println(a[i]);
}
21
42
63
84
可以这样做:
package com;
import java.io.*;
public class test1 { /**
* @param args
*/
public static void main(String[] args) throws IOException {
int a[]=new int[100];
int i;
for( i=0;i<100;i++){
if((i+1)%3==0&&(i+1)%7==0){
a[i]=i+1;
System.out.println(a[i]);
}
}
}
}