打赏

java中的nextLine

package scanner;

import java.util.Scanner;

public class NextLine {
    public static void main(String[] args) {
        //nextLine()方法返回的是enter键之前的字符
        
        Scanner line = new Scanner(System.in);    
        
        //想用两次就直接掉用两次,把nextLine赋值给字符串
        
        String lineStr = line.nextLine();    //hello
        
        String lines = line.nextLine();        //world
        
        
        System.out.println("lineStr: " + lineStr);  //lineStr: hello
        
        System.out.println("lines: " + lines);        //lines: world
    }
}

 

posted @ 2016-03-26 22:20  海米傻傻  阅读(370)  评论(0编辑  收藏  举报