Java + Scanner + next

来源:互联网 发布:遗传算法的书籍 编辑:程序博客网 时间:2024/05/21 07:09

回忆一下以前学习的东西,发现许多东西豁然开朗。


public static void main(String[] args) {Scanner s = new Scanner(System.in);String str1 = s.nextLine();//home workString str2 = s.next();//work homeSystem.out.println(str1);//home workSystem.out.println(str2);//work}

看出结果了没。next()已空格为区分,只读取空格签部分,nextLine()为读取一行以确定键区分。

原创粉丝点击