一、输入
【输入格式】
第一行包含一个整数N。
第二行包含N个整数A1, A2, … AN。
第三行包含N个整数B1, B2, … BN。
第四行包含N个整数C1, C2, … CN。
【样例输入】
3
1 1 1
2 2 2
3 3 3
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n,count=0;
int[][] a = new int[3][100001];
Scanner in = new Scanner(new BufferedInputStream(System.in));
n = in.nextInt();
for(int i=0;i<3;i++)
for(int j=0;j<n;j++)
a[i][j]=in.nextInt();
}
}
输入挂
Scanner in = new Scanner(new BufferedInputStream(System.in));
读一个整数:int n = sc.nextInt();
读一个字符串:String s = sc.next();
读一个浮点数:double t = sc.nextDouble();
读一整行: String s = sc.nextLine();
判断是否有下一个输入sc.hasNext()
或sc.hasNextInt()
或sc.hasNextDouble()
或sc.hasNextLine()
二、文件读写
文件读取
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class 文件读取 {
public static void main(String[] args) {
String pathname = "input.txt";
try (FileReader reader = new FileReader(pathname);
BufferedReader br = new BufferedReader(reader)
) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
文件写入
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class 文件写入 {
public static void main(String[] args) {
try {
File writeName = new File("output.txt");
writeName.createNewFile();
try (FileWriter writer = new FileWriter(writeName);
BufferedWriter out = new BufferedWriter(writer)
) {
out.write("123\r\n");
out.write("1 2 3");
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
大数类
import java.math.BigInteger;
public class 大数类 {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("12") ; // 声明BigInteger对象
BigInteger bi2 = new BigInteger("15") ; // 声明BigInteger对象
System.out.println("加法操作:" + bi2.add(bi1)) ; // 加法操作
System.out.println("减法操作:" + bi2.subtract(bi1)) ; // 减法操作
System.out.println("乘法操作:" + bi2.multiply(bi1)) ; // 乘法操作
System.out.println("除法操作:" + bi2.divide(bi1)) ; // 除法操作
System.out.println("最大数:" + bi2.max(bi1)) ; // 求出最大数
System.out.println("最小数:" + bi2.min(bi1)) ; // 求出最小数
BigInteger result[] = bi2.divideAndRemainder(bi1) ; // 求出余数的除法操作
System.out.println("商是:" + result[0] +
";余数是:" + result[1]) ;
}
}