题解 | #统计输入正数个数#
统计输入正数个数
https://www.nowcoder.com/practice/3266386e460a4e219d6b7d0bed2065b9
import java.util.*; public class Main { public static void main(String[] args) { //write your code here...... Scanner sc=new Scanner(System.in); //定义集合保存元素,遇到0停止添加,返回集合长度-1 ArrayList<Integer> arr=new ArrayList<Integer>(); while(true){ int c=sc.nextInt(); arr.add( c); if(c<=0)break; } System.out.println(arr.size()-1); } }