1.水仙花个数
在控制台输出所有的水仙花数,统计水仙花共有多少个?
public static void main(String[] args) {
//定义三个变量分别来当水仙花数的个位十位和百位
int ge;
int shi;
int bai;
//for循环遍历,从100开始 ,一直到999,
for(int x = 100;x<=999;x++){
int sum;
//个位
ge = x%10;
//十位
shi = x/10%10;
//百位
bai = x/100;
sum = ge*ge*ge+shi*shi*shi+bai*bai*bai;
if(sum == x){
System.out.println(sum);
}
}
}
2.纸张折叠成珠穆朗玛峰高度的次数(求和)
我国最高山峰是珠穆朗玛峰:8848m,我现在有一张足够大的纸张,厚度为:0.01m。请问,我折叠多少次,就可以保证厚度不低于珠穆朗玛峰的高度
public static void main(String[] args) {
double d = 0.01;
double count = 0;
while(d<8848){
d *= 2;
count += 1;
System.out.println("这是第"+count+"次,高度为"+ d +"m");
}
System.out.println("用了"+count+"次");
}
}
3.九九乘法表
public static void main(String[] args) {
for(int x=1;x<=9;x++){
for(int y =1;y<=x;y++){
System.out.print( y +"*"+ x + "="+ x*y+" ");
}
System.out.println();
}
}
}
本文作者:
黄广志
本文链接: https://github.com/ggzhi/ggzhi.github.io/2019/11/22/%E9%80%BB%E8%BE%91%E6%80%9D%E7%BB%B4%E9%A2%98/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!
本文链接: https://github.com/ggzhi/ggzhi.github.io/2019/11/22/%E9%80%BB%E8%BE%91%E6%80%9D%E7%BB%B4%E9%A2%98/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!
![知识共享许可协议](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)