Scanner的useDelimiter方法是支持正则表达式的。假设一个字符串你想通过感叹号或者问号分割,这么写useDelimiter(“[!?]”)就可以了。

import java.util.Scanner;

public class first {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("[,.]");
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d\n",a,b);

    }
}

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
相关资源
相似解决方案