package com.xiaotian.test;
/**
* 打印1-30的奇数和偶数,偶数存在a[],奇数存在 b[]里
* @author xiaotian
*
*/
public class OddNumberAndEvenNumber {
/**
* main主方法
* @param args
*/
public static void main(String[] args) {
int[] a = new int[15];
int[] b = new int[15];
for(int i=1; i<31; i++){
int x = 0, y = 0;
if(i%2==0){//判断是偶数
System.out.println(i+" ");
a[x] = i;//存在a[]里
x++;
System.out.println("a[x]="+a[x]+" ");
}else{//判断是奇数
b[y++] = i;//存在b[]里
}
}
//打印a[]
System.out.print("偶数:a[");
for(int x=0; x<a.length; x++){
if(x != a.length-1)
System.out.print(a[x]+",");
else
System.out.print(a[x]+"]");
}
//打印b[]
System.out.print("奇数:a[");
for(int x=0; x<b.length; x++){
if(x != b.length-1)
System.out.print(b[x]+",");
else
System.out.print(b[x]+"]");
}
}
}
|
|