求数组中能被3整除的元素并打印输出

package com.imooc.array;

public class ArrayDemo2 {

	public static void main(String[] args) {
		//定义一个整型数组,并初始化
		int[] a=new int[15];	
		//循环遍历数组,找出能被3整除的元素并打印输出
		for(int i=0;i<15;i++){
			a[i]=i+1;
			//System.out.print(a[i]+" ");
			}
		System.out.println("能被3整除的数组元素为:");
		for(int i=5;i<a.length;i++){
			if(a[i]%3==0){
				if(a[i]/3!=3)
				System.out.println(a[i]+" ");
			}
			
			}
		}
}

  

posted @ 2017-12-26 16:08  振华213  阅读(2464)  评论(0编辑  收藏  举报