...1)的程序中(I=1...100) 用JAVA程序编写(书面)
发布网友
发布时间:2024-09-30 04:21
我来回答
共3个回答
热心网友
时间:2024-10-07 09:00
不应该直接给代码,如果你觉得自己的代码有问题,可以贴出来大家帮忙看一下,直接给代码不是学习之道啊
热心网友
时间:2024-10-07 08:59
public class for_test{
int i,sum=0;
for(i=1; i<100;i+2 )
{
sum=sum+i;
System.out,print(sum);
}
}
public class while_test{
int i,sum=0;
while( i<=100 )
{
sum=sum+i;
i=i+2;
System.out,print(sum);
}
}
public class while_test{
int i,sum=0;
do
{
sum=sum+i;
i=i+2;
System.out,print(sum);
}while( i<100 )
}
热心网友
时间:2024-10-07 09:00
==============程序代码 Calc.java===============================
class Calc
{
public static void main(String args[])
{
int sum = 0;
// 1。用for
for (int i=1;i<=100;i++)
sum+=2*i+1;
System.out.println("Use For, sum="+sum);
// 2。用while
sum = 0;
int counter = 1;
while (counter<=100) {
sum+=2*counter+1;
counter++;
}
System.out.println("Use while, sum="+sum);
// 3。用do,while
sum = 0;
counter = 1;
do {
sum+=2*counter+1;
counter++;
} while (counter<=100) ;
System.out.println("Use do while, sum="+sum);
}
}
==================运行结果===============================
Use For, sum=10200
Use while, sum=10200
Use do while, sum=10200