• Scanner和BufferedReader


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;
    
    
    public class DemoScanner {
        
        //打印
        public static void printScanner() {
            Scanner s = new Scanner(System.in);
            System.out.println("请输入字符串:");
            while (true) {
                String line = s.nextLine();
                if (line.equals("exit"))
                    break;
                System.out.println(">>>" + line);
            }
        }
    
        //自定义换行符
        public static  void lnScanner() {
            Scanner s = new Scanner("123 asdf sd 45 789 sdf asdfl,sdf.sdfl,asdf    ......asdfkl    las");
            s.useDelimiter(" |,|\.");
            while (s.hasNext()) {
                System.out.println(s.next());
            }
        }
        //InputStreamReader类比scanner效率高,其中的BufferedReader类中对象只生成一次,以后可以重复使用,这就是效率高的原因。
         private static String readString(String prompt) {
             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
             String str = null;
            try {
                 System.out.print(prompt);
                 str = br.readLine();
             } catch (IOException e) {
                 e.printStackTrace();
             }
            return str;
         }
         
         public static void main(String[] args) {
             String str = readString("请输入字符串:");
             System.out.println("readString6 方法的输入:" + str);
        }
    }
  • 相关阅读:
    js正则表达式
    js遍历对象属性
    C# 带Cookies发送请求
    C# Cookies设置和读取
    C# ref 和 out 的使用
    jq 禁用复选框 和输入框
    C++学习之嵌套类和局部类
    C++学习之this指针
    C++学习之运算符重载的总结
    Labview中引用,属性节点,局部变量之间的区别
  • 原文地址:https://www.cnblogs.com/sprinng/p/5643317.html
Copyright © 2020-2023  润新知