import java.util.Scanner;
public class NumberCount {
public int NumberCount(int n){
int sum=0;
int count=(n+1)/2;//求出循环次数count
for(int i=0;i
}
return sum;
}
public static void main(String[] args) {
System.out.print("你输入的n为:");
NumberCount test=new NumberCount();//实例化类对象
Scanner input=new Scanner(System.in);//获取在键盘输入的字
int j=input.nextInt();//通过nextInt()方法获得你自己输入的数字n
System.out.println("你得到的结果为:"+test.NumberCount(j));//输出结果
}
}
public static int sum(int n) {
if (n < 1) {
throw new IllegalArgumentException("参数n不能小于1。");
}
int sum = 0;
int f = 0;
for (int i = 1; i <= n; i++) {
int x = 2 * f + 1;
sum += x;
f = x;
}
return sum;
}