java Scanner next方法 nextLine方法
// 创建Scanner对象 Scanner scan = new Scanner(System.in); // 阻塞等待用户输入数据 if (scan.hasNext()) { String text = scan.next(); System.out.println("输入的数据为:" + text); } // 关闭 scan.close(); next注意点: (1).next方法是阻塞的,直到它等到用户输入数据 (2).next方法遇到空白字符串后的字符都会丢弃(不知道我解释是否准确),例如aaaaaa f只能输出例如aaaaaa 而nextLine方法是没有此问题的 // 创建Scanner对象 Scanner scan = new Scanner(System.in); // 阻塞等待用户输入数据 if (scan.hasNextLine()) { String text = scan.nextLine(); System.out.println("输入的数据为:" + text); } // 关闭 scan.close(); Scanner对象还支持对输入数据类型的支持,例如 // 创建Scanner对象 Scanner scan = new Scanner(System.in); // 定义接收字符串 int number = 0; // 输入整数测试 if (scan.hasNextInt()) { number = scan.nextInt(); System.out.println("输入的是整数数据:" + number); } else { System.out.println("输入的不是整数"); } // 关闭 scan.close();
(1).final 修饰符通常和 static 修饰符一起使用来创建类常量。(2).父类中的 final 方法可以被子类继承,但是不能被子类重写,声明 final 方法的主要目的是防止该方法的内容被修改。public class Member {  ...
在java中字符串属于对象,刚开始我就疑惑为什么int char等类型都是小写,结果String是大写,java太反人类,后来才知道String是对象。(1).java创建字符串String text = "net"; String tex...
(1).java睡眠函数Thread.sleep(时间); //单位为毫秒(2).java睡眠函数例子Date dNow = new Date(); SimpleDateFormat ft = new&nbs...
(4).java lookingAt匹配字符串和java matches匹配字符串lookingAt不要求整个字符串全匹配,例如me和me_you都是匹配的,但是lookingAt从第一个字符串开始匹配,匹配失败了也不会继续匹配,意味着me和you_me是无法匹配的matches匹配字符串要求全部匹...
假如有个字符串为"fatcatfatcatfat",正则为“cat”当调用appendReplacement(sb, "dog")时appendReplacement方法都会把匹配到的内容替换为dog,并把匹配到字符串的前面几个字符串+dog送给sb里,所以第...
java 可变参数// 定义方法 public static int sum(int... number) { int result = 0; &nb...