array1[count] !=1这个条件,把数组中值为1的排除了,所以出现你上面说的情况。

解决方案 »

  1.   

    要想实现叔祖的复制,我给你修改了一下代码:
    class CopyArrayWhile {
        public static void main(String[] arguments) {
            int[] array1 = { 7, 4, 8, 1, 4, 1, 4 };
            float[] array2 = new float[array1.length];        System.out.print("array1: [ ");
            for (int i=0; i<array1.length; i++) {
            System.out.print(array1[i] + "; ");
            }
            System.out.println("]");        System.out.print("array2: [ ");
            int count=0;
            while ( count<array1.length ) {
            array2[count]=(float) array1[count];
            System.out.print(array2[count++] + ";");
            }        System.out.println("]");        
       }
    }
      

  2.   

    输出结果:
    ---------- java ----------
    arraylength=7
    array1: [ 7; 4; 8; 1; 4; 1; 4; ]
    array2: [ 7.0 ;4.0 ;8.0 ;1.0 ;4.0 ;1.0 ;4.0 ;]
    Normal Termination
    Output completed (0 sec consumed).
    看看,这是你要的结果吗?
      

  3.   

    while ( count<array1.length && array1[count] !=1)
    你的循环条件这么写的话,当遇到array1中的第一个1时,条件就不满足了,所以循环就终止了,后面的两个4也就没有输出。
    你要想达到过滤掉array1中的两个1的目的,可以这么写:
    public class CopyArrayWhile {
        public static void main(String[] arguments) {
            int[] array1 = { 7, 4, 8, 1, 4, 1, 4 };
            float[] array2 = new float[array1.length];        System.out.print("array1: [ ");
            for (int i=0; i<array1.length; i++) {
            System.out.print(array1[i] + " ");
            }
            System.out.println("]");        System.out.print("array2: [ ");
            int count1 = 0;
            int count2 = 0;
            while ( count1 < array1.length )  {
              if(array1[count1] != 1){
                array2[count2]=(float) array1[count1];
                System.out.print(array2[count2++] + " ");
              }
              count1++;
            }        System.out.println("]");
       }
    }
      

  4.   

    循环条件array1[count] !=1使得你遇到数组array1的第一个等于1的值时,循环就停止了!
      

  5.   

    同意 zwzhero(令狐冲) 
    你应该这样写
    while ( count<array1.length ) {
    if (array1[count] !=1)
    {
            array2[count]=(float) array1[count];
            System.out.print(array2[count++] + " ");
    }
            }