求數組中能被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]+" ");
			}
			
			}
		}
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM