Max


私信TA

用户名:1710958430

访问量:2298

签 名:

bug多如牛毛!

等  级
排  名 1925
经  验 2458
参赛次数 2
文章发表 6
年  龄 23
在职情况 在职
学  校 保定职业技术学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:


import java.util.Arrays;

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner sc=new Scanner(System.in);

       int n=sc.nextInt();

       int m[]=new int[n];

       int z=0;

       for (int i=0;i<m.length;i++){

           m[i]=sc.nextInt();

       }

       for (int ij=0;ij<m.length;ij++) {

           for (int j = 0; j < m.length - 1; j++) {

               if (m[j] == 0) {           //交换

                   m[j] = m[j + 1];

                   m[j+1]=0;

               }

           }

       }

       for (int k=0;k<n;k++){

           if(m[k]==0){

               z++;

           }

       }
               
       m = Arrays.copyOf(m, m.length-z); //缩短数组

       for (int x=0;x<m.length;x++){

           System.out.printf(m[x]+" ");

       }

       System.out.printf("\n");

       System.out.printf(""+m.length);

   }

}

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区