目录
1. 入门训练 A+B问题
Problem:
Hint:复制粘贴就行了
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); Integer a = sc.nextInt(); Integer b = sc.nextInt(); System.out.println(a + b); } }
2.入门训练 序列求和
Problem:
Hint:用公式n*(n+1)/2就行
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextInt(); System.out.println((1+n)*n/2); } }
3.入门训练 圆的面积
Problem:
Hint:PI*r²
import java.text.DecimalFormat; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); DecimalFormat format = new DecimalFormat("0.0000000"); int r = in.nextInt(); System.out.println(format.format(Math.PI*r*r)); } }
4.入门训练 Fibonacci数列
Problem:
Hint:直接Fn=(Fn-1+Fn-2)%10007
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] nums = new int[1000000]; nums[0] = 1; nums[1] = 1; for (int i = 2; i < nums.length; i++) { nums[i] = (nums[i-1]+nums[i-2])%10007; } int n = in.nextInt(); System.out.println(nums[n-1]); } }