题目链接
找规律,经观察:第一项为n(n-1)+1,最后一项为n(n+1)-1,把中间的数print一下就ok
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); while(in.hasNext()){ int n=in.nextInt(); int start=n*(n-1)+1; int end=n*(n+1)-1; for(int i=start;i<=end;i+=2){ if(i==end){ System.out.println(i); } else System.out.print(i+"+"); } } } }