java题目 (基础)

来源:百度知道 编辑:UC知道 时间:2024/05/08 01:59:59
1.本金10000元存入银行,年利率是千分之三,每过一年,将本金和利息相加作为新的本金,计算5年后,获得本金是多少?
要求:java编写,运用while循环。要简洁
2。计算1000以内所有不能被7整除的整数的和?
要求同上

public class bank
{

public static void main(String[] args)
{
int year = 5;
double principal = 10000;//本金
double rate = 0.003;//利率
double amount = 0 ;//本利和

int count = 1;//计数器

while( count <= year )
{
amount = principal*Math.pow( 1+rate , count );
System.out.printf("第%d年本利和:%,.2f\n",count, amount);
count++;
}

}

}

public class Test01
{
public static void main( String args[] )
{
int a=0;

for(int i=0 ; i<1000 ;i++)
{
if( i%7 != 0 )
{
a=a+i;
}
}
System.out.print("1000以内所有不能被7整除的整数的和:"+a);
}
}

上面已经有人做出详细的回答,我就不多嘴了.

这问题太菜了,简单的都不想说了

int x=0;
double ss=10000;
while(x<n){
ss += ss*0.003;
x +=1;
}
System.out.println(String.valueOf(ss));

NO.2