import java.util.*; public class Main { public static void main(String[] args) { int count = 0; Scanner sc = new Scanner(System.in); while(sc.hasNextInt()){ int x = sc.nextInt(); if(x>0){ count++; }else if(x<=0){ break; } } System.out.println(count); } }
直接用hasNextInt()