JAVA常用STL

这篇博客详细介绍了Java中的标准模板库(STL)替代品,包括输入输出方法、大整数BigInteger和高精度BigDecimal的使用,以及字符串的基本操作和进制转换。此外,还深入讲解了Java的数据结构,如HashSet、HashMap、ArrayList、PriorityQueue、ArrayDeque和Stack的用法及其与C++ STL的对应关系。
摘要由CSDN通过智能技术生成

输入与输出

1.输入

  • 基本输入
Scanner sc=new Scanner(System.in);
Scanner in = new Scanner (new BufferedInputStream(System.in));//更快
  • 输入格式
1. 只有一组数据:

    Scanner sc=new Scanner(System.in);
    int a=s.nextInt();
    int b=s.nextInt();

2. 输入多组数据,不告知组数,也没有截止符

    Scanner sc=new Scanner(System.in);
    while(sc.hasNext()){
   //判断是否数据结束
        int a=s.nextInt();
        int b=s.nextInt();
    }

3. 输入多组数据,不告知组数,截止符为ch

	Scanner sc=new Scanner(System.in);
	while(sc.hasNext()){
   
		int c=sc.nextInt();
		if(c==ch) return;
	}

4. 输入多组数据,第一行是整数N,表示有N组数据,之后每行表示一组数据

  
    int n;
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    for(int i=0;i<n;i++){
   
       int a=sc.nextInt();
       int b=sc.nextInt();
    }

5.养成良好习惯,最后关闭输入流
	
	sc.close();
  • 输入挂(当输入规模达到106的时候,就需要输入挂,否则很有可能超时)
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main
{
   
 
    public static void main(String[] args)
    {
   
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        out.close();
    }
}
class InputReader
{
   
    BufferedReader buf;
    StringTokenizer tok;
    InputReader()
    {
   
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext()
    {
   
        while(tok == null || !tok.hasMoreElements()) 
        {
   
            try
            {
   
                tok = new StringTokenizer(buf.readLine());
            } 
            catch(Exception e) 
            {
   
                return 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值