Java语法回顾

  • 输入
  • import java.util.Scanner;//引入输入函数
    
    Scanner sc=new Scanner(System.in);//创建对象
    
    int n = sc.nextInt();//输入的存到n中去
    
    long sum=0//用长整数来保存
  • 模块化:当需要完成某个操作时,比如判断是否是符合条件的加法的数,可以单独写一个函数,返回值为boolean,通过返回值来判断是否符合,符合则加上

 语法错误

  1. 在创建数组new int 【n】,不用加上数组名字,若是加上就是错的

快读模板

import java.util.Scanner;
import java.io.*;
import java.util.StringTokenizer;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        int t=1;
        for(int i=1;i<=t;i++){
          solve();
        }
        out.flush();
    }

    static void solve(){

    }

    static FastReader in=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);

    static class FastReader{
      static BufferedReader br;
      static StringTokenizer st;

      FastReader{
        br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next(){
        String str="";
        while(st==null||!st.hasMoreElements()){
          try{
            str=br.readLine();
          }catch(IOException e){
            throw new RuntimeException(e);
          }
          st=new StringTokenizer(str);
        }
        return st.nextToken();
      }
      int nextInt(){
        return Integer.parseInt(next());
      }

      int nextDouble(){
        return Double.parseDouble(next());
      }

      int nextLong(){
        return Long.parseLong(next());
      }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值