/**
*
*实巧毕和用for循环计算孝盯8+88+888+8888.。。。前10项之和
*
*/
public class Sum1 {
public static void main(String[] args) {
long s = 0L;
int a = 8, c;
for (int i = 0; i < 10; i++) {
s += a;
c = a;
c *= 10;
a += c;
}
System.out.println(s);
}
}
第二个问题7.926210728149432*10^374超数乎过了Double的范围
代码如下,输出为Infinity
public class Sum2{
public static void main(String[] args) {
double s=0.0,t=1.0;
for (int i = 100; i <=200; i++) {
for(int j=1;j<=i;j++)
t*=j;
s+=t;
t=1;
}
System.out.println(s);
}
}
for(int i=1;i<=10;++i)
{
String s="8888888888888";
System.out.print(s.substring(0,i)+"+");
}
for(inti=100;i<=200;++i)
{
System.out.print(i+"!+"蚂世);
}
量和察身定闷棚肢做