当前位置: 代码迷 >> 综合 >> 练习:hasNext()与Next()的不同
  详细解决方案

练习:hasNext()与Next()的不同

热度:19   发布时间:2024-01-09 04:10:12.0

本文为博主原创文章,未经博主允许不得转载。

hasNext...()读取下一个目标,判断它是否存在

hasNextLine()

hasNextInt()

Next....()读取输入的字符,以空格为分隔符,返回输入的字符

nextLine()读入当前一行

nextInt()读入当前一个整型数据

next()读入字符直到出现第一个空格停下

import java.util.*;
public class prc {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc=new Scanner(System.in);while(sc.hasNextInt())//可以参考下C中的EOF{int s=sc.nextInt();System.out.print(s);}sc.close();}}