编程技巧系列(7)java中从控制台输入多行数据 按回车键输入空行结束

public static void main(String[] args)
    {
        StringBuilder stringbuilder = new StringBuilder();
        Scanner scanner = new Scanner(System.in);
        while(true)
        {
            String text = scanner.nextLine().trim();
            if ("".equals(text))
            {
                break;
            }
            stringbuilder.append(text);
        }
        
        System.out.println(stringbuilder.toString());
    }

你可能感兴趣的:(java基础)