Language: Java

import java.util.*;
public class Main {
 static int i;//i:蓝球连续排列的个数(s:红球连续排列的个数）
 static long res=0;
 static long M=1000000007;
 public static void main(String []args) {
  Scanner sc=new Scanner();
   int n=sc.nextInt();
   int k=sc.nextInt();
   balls(n,k);
 }
 //排序方法一共有n!/(k!*(n-k)!)
 
 public static long balls(int n,int k) {
   for(i=1;i<=k;i++) {
   if(n==2*k) {
    if(i==1|| (i-1)==k || i==k) {
        res=n-k+1;
        System.out.println(res%M);
       }
    else {
        res=2*comb(k-1,i-1)*comb(n-k-1,i-1)+comb(k-1,i-1)*comb(n-k-1,i)+comb(k-1,i-1)*comb(n-k-1,i-2);
        System.out.println(res%M);
       }    
   }
   if(n>2*k) {
    if(i==1|| (i-1)==k) {
        res=n-k+1;
        System.out.println(res%M);
       }
    else {
        res=2*comb(k-1,i-1)*comb(n-k-1,i-1)+comb(k-1,i-1)*comb(n-k-1,i)+comb(k-1,i-1)*comb(n-k-1,i-2);
        System.out.println(res%M);
       }
   }
   if(n<2*k) {
    if(i==1) {
        res=n-k+1;
     System.out.println(res%M);
    }
    else if(i!=k){
        res=2*comb(k-1,i-1)*comb(n-k-1,i-1)+comb(k-1,i-1)*comb(n-k-1,i);
        System.out.println(res%M);
     }
    else {
     res=comb(k-1,i-1)*comb(n-k-1,i);
     System.out.println(res%M);
    }
       }
   }
   return res;
 }
//i==s:排列方式有2*comb(k-1,i-1)*comb(n-k-1,i-1)
//i==s-1ori==s+1:排列方式有comb(k-1,i-1)*comb(n-k-1,i-1)
 
 
/*
 * 11 12 11
 * 22 21 22 22 22 21
 * 32
 */

 public static long comb(int n,int k) {
  int i,j;
  if(n>=2*k) {
   i=n-k+1;
   j=k;
  }
  else {
   i=k+1;
   j=n-k;
  }
  return (pf(i,n)/pf(1,j))%M;
 }
 
 static long pf(int m,int n) {
  long i,f;
  f=1;
  for(i=m;i<=n;i++) {
   f=(f*i)%M;
  }
  return f;
 }
}


Compiler output:
Main.java:7: error: no suitable constructor found for Scanner(no arguments)
  Scanner sc=new Scanner();
             ^
    constructor Scanner.Scanner(Readable,Pattern) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Readable) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,CharsetDecoder) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel,Charset) is not applicable
      (actual and formal argument lists differ in length)
1 error