猿问
下载APP

JAVA怎样实现数组不输出数据为0的元素?

比如:int[] arr={0,1,0,2,0,5},怎样实现在输出的时候不显示0,输出结果为1,2,5

chrome1121
浏览 10187回答 21
21回答

道临

for(int i: arr){     if(i==0){         continue;     }else{         System.out.println(i);     } }

qq_雁过留声_2

for(int i: arr){     if(i != 0) System.out.println(i); }代码应该尽量简洁,望采纳

Teemo_

Arrays.stream(arr).filter(item -> item != 0).forEach(System.out::println);滑稽

qq_炫_03909954

public class Test {     public static void main(String[] args) {        int[] arr = {0,1,0,2,0,5};        Arrays.stream(arr).filter(item->item!=0).forEach(System.out::println);     } }

Super_Scholar

for(int i: arr){    i==0?continue:System.out.println(i);     }

weibo_projecedp_0

for(int i=1;i<arr.length;i+=2)这个例子这样也行

qq_小鹏哥_0

for(int i = 0; i<arr.length; i++){            if(arr[i] != 0){                        System.out.print(arr[i] + " \t");                                        }    }

慕粉3835723

遍历数组,输出前加判断

慕莱坞4347929

多学多看.................................................

慕标0481585

https://www.hao123.com/manhua/list/?cate=%E5%8E%8B%E7%BC%A9%E6%B0%94%E5%8A%A8%E6%8A%A2%E6%9C%89%E5%A4%9A%E5%A4%A7%E5%A8%81%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91VSshttps://www.hao123.com/manhua/list/?cate=%E4%B8%80%E4%B8%AA%E7%9C%9F%E5%AE%9E%E5%85%AB%E5%80%8D%E9%95%9C%E7%9A%84%E4%BB%B7%E6%A0%BC%E3%80%9094003O11.Q%28mk%29%E3%80%91zuahttps://www.hao123.com/manhua/list/?cate=%E7%8C%8E%E6%8A%A2%E5%BA%95%E7%81%AB%E5%8F%AF%E7%94%A8%E4%BB%80%E4%B9%88%E4%BB%A3%E6%9B%BF%E3%80%9094003O11.Q%28mk%29%E3%80%91zXthttps://www.hao123.com/manhua/list/?cate=%E7%89%9B%E4%BA%BA%E8%86%9B%E7%BA%BF%E7%AE%80%E5%8D%95%E5%88%B6%E4%BD%9C%E6%96%B9%E6%B3%95%E3%80%9094003O11.Q%28mk%29%E3%80%91CA3https://www.hao123.com/manhua/list/?cate=%E6%9C%89%E4%BB%80%E4%B9%88%E6%96%B9%E6%B3%95%E5%8F%AF%E4%BB%A5%E6%90%9E%E5%88%B0%E6%8A%A2%E3%80%9094003O11.Q%28mk%29%E3%80%91jOQhttps://www.hao123.com/manhua/list/?cate=%E5%8F%AF%E4%BB%A5%E5%8F%91%E5%B0%84%E5%AD%90%E5%BC%B9%E7%9A%84%E6%8A%A2%E5%A4%A7%E5%85%A8%E3%80%9094003O11.Q%28mk%29%E3%80%91VuKhttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E6%B7%98%E5%AE%9D%E4%B8%8A%E6%80%8E%E4%B9%88%E6%89%BE%E7%87%95%E5%B0%BE%E3%80%9094003O11.Q%28mk%29%E3%80%91AQ7https://www.hao123.com/manhua/list/?cate=%E5%9B%BD%E4%BA%A7%E7%A7%83%E5%AD%90%E4%B8%AD%E6%8F%A1%E5%85%A8%E5%A5%97%E4%BB%B7%E6%A0%BC%E3%80%9094003O11.Q%28mk%29%E3%80%91F93https://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E7%9A%84%E5%88%9D%E9%80%9F%E7%A8%B3%E5%AE%9A%E6%80%8E%E4%B9%88%E8%B0%83%E3%80%9094003O11.Q%28mk%29%E3%80%91W5mhttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90280%E5%88%9D%E9%80%9F%E5%A4%9A%E5%B0%91%E7%84%A6%E8%80%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91A5Zhttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E6%97%A0%E8%86%9B%E7%BA%BF%E8%83%BD%E6%89%93%E5%A4%9A%E8%BF%9C%E3%80%9094003O11.Q%28mk%29%E3%80%91O32https://www.hao123.com/manhua/list/?cate=%E6%8D%B7%E5%85%8B%E6%9D%BF%E7%90%83%E5%A4%9A%E5%B0%91%E9%92%B1%E4%B8%80%E6%94%AF%E3%80%9094003O11.Q%28mk%29%E3%80%91IwEhttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E6%81%92%E5%8E%8B%E9%AB%98%E6%9C%89%E4%BB%80%E4%B9%88%E5%BD%B1%E5%93%8D%E3%80%9094003O11.Q%28mk%29%E3%80%91DTUhttps://www.hao123.com/manhua/list/?cate=%E6%8D%B7%E5%85%8B%E6%9D%BF%E7%90%83100%E7%B1%B3%E6%89%93%E9%B8%9F%E8%A7%86%E9%A2%91%E3%80%9094003O11.Q%28mk%29%E3%80%91LSxhttps://www.hao123.com/manhua/list/?cate=%E6%9D%BF%E7%90%83%E4%B8%80%E4%BD%93%E9%95%9C%E6%A1%A5%E4%BB%B7%E6%A0%BC%E3%80%9094003O11.Q%28mk%29%E3%80%91XtFhttps://www.hao123.com/manhua/list/?cate=%E5%B9%BF%E5%8D%8E%E8%A1%97%E4%B9%B0%E7%8B%97%E6%8B%86%E5%BC%80%E8%83%BD%E8%BF%87%E5%85%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91rZfhttps://www.hao123.com/manhua/list/?cate=%E4%B8%89%E7%AE%AD4.5%E8%80%81%E7%8B%97%E6%94%B9p%E7%B2%BE%E5%BA%A6%E3%80%9094003O11.Q%28mk%29%E3%80%91sPJhttps://www.hao123.com/manhua/list/?cate=%E4%B8%80%E6%8A%8A%E7%9F%AD%E7%A7%83%E9%9C%80%E8%A6%81%E4%BB%80%E4%B9%88%E9%85%8D%E4%BB%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91l40https://www.hao123.com/manhua/list/?cate=%E5%9B%BD%E4%BA%A75.5%E6%9D%BF%E7%90%83%E6%9C%89%E6%95%88%E5%B0%84%E7%A8%8B%E3%80%9094003O11.Q%28mk%29%E3%80%91g6dhttps://www.hao123.com/manhua/list/?cate=diy%E5%86%B2%E5%AD%90%E9%A1%B6%E7%AE%A1%E6%8A%80%E6%9C%AF%E4%BA%A4%E6%B5%81%E3%80%9094003O11.Q%28mk%29%E3%80%91sAKhttps://www.hao123.com/manhua/list/?cate=%E7%8B%A9%E7%8C%8E%E9%87%8E%E7%8C%AA%E5%B7%A5%E5%85%B7%E7%8B%A9%E7%8C%8E%E9%87%8E%E9%B8%A1%E5%B7%A5%E5%85%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91gG1https://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%86%85%E8%84%8F%E5%85%A8%E5%A5%97%E9%85%8D%E4%BB%B6%E5%A4%9A%E5%B0%91%E9%92%B1%E3%80%9094003O11.Q%28mk%29%E3%80%91Vj7https://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E5%85%89%E7%9E%84%E6%A0%A1%E5%87%86%E6%96%B9%E6%B3%95%E5%9B%BE%E8%A7%A3%E3%80%9094003O11.Q%28mk%29%E3%80%91PYbhttps://www.hao123.com/manhua/list/?cate=%E6%B7%98%E5%AE%9D%E6%80%8E%E4%B9%88%E6%90%9C%E7%B4%A2%E6%9D%BF%E7%90%83%E9%85%8D%E4%BB%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91KH7https://www.hao123.com/manhua/list/?cate=%E8%BF%B7%E4%BD%A0%E7%A7%83%E5%A4%9A%E5%B0%91%E9%92%B1%E7%9F%AD%E6%89%8B%E7%A7%83%E5%9B%BE%E7%89%87%E3%80%9094003O11.Q%28mk%29%E3%80%91G8phttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E7%9F%AD%E6%AC%BE%E5%A5%BD%E8%BF%98%E6%98%AF%E9%95%BF%E6%AC%BE%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91wWrhttps://www.hao123.com/manhua/list/?cate=m9a1%E7%94%A8%E5%A4%9A%E5%A4%A7%E7%9A%84%E9%92%A2%E7%8F%A0%E5%BC%B9%E3%80%9094003O11.Q%28mk%29%E3%80%91NRzhttps://www.hao123.com/manhua/list/?cate=%E6%81%92%E5%8E%8B%E9%98%80%E5%A6%82%E4%BD%95%E6%94%B9%E8%A3%85%E8%BF%9E%E5%8F%91%E6%8E%92%E3%80%9094003O11.Q%28mk%29%E3%80%91x2Ohttps://www.hao123.com/manhua/list/?cate=pcp%E6%9D%BF%E7%90%83%E6%9C%A8%E6%89%98%E5%B0%BA%E5%AF%B8%E5%9B%BE%E3%80%9094003O11.Q%28mk%29%E3%80%91O66https://www.hao123.com/manhua/list/?cate=%E7%87%95%E5%B0%BE%E5%9E%8B%E6%9D%9055cm%E5%86%85%E5%BE%84%E5%A4%9A%E5%B0%91%E3%80%9094003O11.Q%28mk%29%E3%80%91B89https://www.hao123.com/manhua/list/?cate=%E6%9D%BF%E7%90%83%E5%86%85%E7%BD%AE%E6%81%92%E5%8E%8B%E9%98%80%E7%BB%B4%E4%BF%AE%E3%80%9094003O11.Q%28mk%29%E3%80%91rLthttps://www.hao123.com/manhua/list/?cate=6.35%E9%93%85%E5%BC%B9%E8%83%BD%E6%89%93%E6%AD%BB%E9%87%8E%E7%8C%AA%E5%90%97%E3%80%9094003O11.Q%28mk%29%E3%80%91E34https://www.hao123.com/manhua/list/?cate=%E7%BC%85%E7%94%B8%E5%B0%8F%E5%8B%90%E6%8B%89%E6%8A%A2%E5%B8%82%E5%9C%BA%E3%80%9094003O11.Q%28mk%29%E3%80%91ku1https://www.hao123.com/manhua/list/?cate=%E4%BB%80%E4%B9%88%E7%89%8C%E5%AD%90%E7%9A%84%E5%B0%84%E9%92%89%E6%8A%A2%E6%9C%80%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91blJhttps://www.hao123.com/manhua/list/?cate=%E4%B8%89%E7%AE%AD%E7%89%8Cb52%E5%92%8Cb56%E5%93%AA%E4%B8%AA%E5%A5%BD%E3%80%9094003O11.Q%28mk%29%E3%80%91eolhttps://www.hao123.com/manhua/list/?cate=%E9%9B%B7%E9%B8%A3%E5%9E%8B%E5%8F%B7%E4%B8%83%E8%BF%9E%E5%8F%91%E6%89%93%E7%8C%8E%E6%8A%A2%E3%80%9094003O11.Q%28mk%29%E3%80%91Hk0https://www.hao123.com/manhua/list/?cate=%E7%9F%AD%E7%A7%83%E5%A4%A7%E6%A6%82%E5%8D%96%E5%A4%9A%E5%B0%91%E9%92%B1%E4%B8%80%E6%8A%8A%E3%80%9094003O11.Q%28mk%29%E3%80%91IhHhttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E6%80%BB%E5%85%B1%E6%9C%89%E5%A4%9A%E5%B0%91%E4%B8%AA%E9%85%8D%E4%BB%B6%E3%80%9094003O11.Q%28mk%29%E3%80%91sFChttps://www.hao123.com/manhua/list/?cate=%E7%8B%97%E7%B2%AE%E9%85%8D%E4%BB%B6%E6%8A%93%E7%8C%AB%E4%B8%93%E7%94%A8%E5%B7%A5%E5%85%B7%E3%80%9094003O11.Q%28mk%29%E3%80%91DkShttps://www.hao123.com/manhua/list/?cate=%E5%93%AA%E9%87%8C%E6%9C%89%E5%B8%A6%E8%86%9B%E7%BA%BF%E7%9A%84%E7%B2%BE%E5%AF%86%E7%AE%A1%E3%80%9094003O11.Q%28mk%29%E3%80%91JzGhttps://www.hao123.com/manhua/list/?cate=%E9%AB%98%E5%8E%8B%E6%89%93%E6%B0%94%E7%AD%92%E5%8A%A9%E5%8A%9B%E5%99%A8%E5%88%B6%E4%BD%9C%E3%80%9094003O11.Q%28mk%29%E3%80%91OZjhttps://www.hao123.com/manhua/list/?cate=%E4%BA%94%E5%9B%9B%E5%86%9B%E7%94%A8%E5%93%AA%E9%87%8C%E6%9C%89%E5%8D%9654%E7%81%AB%E7%8B%97%E3%80%9094003O11.Q%28mk%29%E3%80%91ErChttps://www.hao123.com/manhua/list/?cate=%E5%93%AA%E9%87%8C%E6%9C%89%E7%81%AB%E7%8B%97%E3%80%9094003O11.Q%28mk%29%E3%80%91KC9https://www.hao123.com/manhua/list/?cate=%E9%95%BF%E6%B2%99%E7%A7%83%E4%B8%80%E5%A4%9A%E5%B0%91%E9%92%B1%3F%E3%80%9094003O11.Q%28mk%29%E3%80%91t91https://www.hao123.com/manhua/list/?cate=%E5%BF%AB%E5%90%B9%E5%AE%89%E8%A3%85%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B%E3%80%9094003O11.Q%28mk%29%E3%80%91k2Yhttps://www.hao123.com/manhua/list/?cate=cp99%E5%A8%81%E5%8A%9B%E8%83%BD%E6%89%93%E5%A4%9A%E5%B0%91%E7%B1%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91KHFhttps://www.hao123.com/manhua/list/?cate=%E6%B7%98%E5%AE%9D654k%E6%9A%97%E8%AF%AD%E7%A7%83%E7%B2%AE%E9%A3%9F%E3%80%9094003O11.Q%28mk%29%E3%80%91o91https://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E5%8F%91%E7%83%A7%E5%8F%8B%E8%AE%BA%E5%9D%9B%E6%89%8B%E6%8B%89%E6%9C%BA%E8%AE%BA%E5%9D%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91m1Rhttps://www.hao123.com/manhua/list/?cate=%E6%89%93%E9%93%85%E5%BC%B9%E6%8A%A2%E9%85%8D%E4%BB%B6%E5%90%8D%E7%A7%B0%E3%80%9094003O11.Q%28mk%29%E3%80%91fJmhttps://www.hao123.com/manhua/list/?cate=%E5%93%AA%E9%87%8C%E6%9C%89%E4%BA%94%E5%9B%9B%E6%89%8B%E6%8A%A2%E3%80%9094003O11.Q%28mk%29%E3%80%91Qh1https://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E7%9C%9F%E5%95%86%E7%A7%83%E5%AD%90%E6%88%B7%E5%A4%96%E3%80%9094003O11.Q%28mk%29%E3%80%91hdahttps://www.hao123.com/manhua/list/?cate=%E4%B8%80%E8%88%AC%E6%89%93%E5%BC%B9%E5%BC%93%E7%94%A8%E5%87%A0%E6%AF%AB%E7%B1%B3%E5%BC%B9%E7%8F%A0%E5%A5%BD%E7%94%A8%E3%80%9094003O11.Q%28mk%29%E3%80%91u6ehttps://www.hao123.com/manhua/list/?cate=%E4%B8%80%E8%88%AC%E7%9A%84%E7%A7%83%E5%AD%90%E7%B2%BE%E5%BA%A6%E5%A4%9A%E5%B0%91%E7%B1%B3%E3%80%9094003O11.Q%28mk%29%E3%80%91A3Khttps://www.hao123.com/manhua/list/?cate=%E7%A7%83%E5%AD%90%E7%B2%BE%E5%BA%A6%E5%A4%9A%E5%B0%91%E5%9B%BD%E7%A7%83%E5%A8%81%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91N4Vhttps://www.hao123.com/manhua/list/?cate=%E7%8E%B0%E5%9C%A8%E5%9B%BD%E7%A7%83%E5%B0%84%E7%A8%8B%E5%92%8C%E5%A8%81%E5%8A%9B%E3%80%9094003O11.Q%28mk%29%E3%80%91pqg
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答
继续浏览精彩内容
慕课网APP
程序员的梦工厂
继续