解题思路:
巧用hasNext()和in.next(),计数即可
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int cnt = 0; while(in.hasNext()) { in.next(); cnt++; } System.out.println(cnt); in.close(); } }
0.0分
4 人评分