1. 打印输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其中各位数字立方和等于该数本身。例如,153是一个“水仙花数”。

实验源码:

public class number1 {
public static void main (String[] args){
int i,j;
int unit,decade,hundreds;
for(i=100;i<=999;i++){
hundreds = i/100;
j = i%100;
decade = j/10;
unit = j%10;
if(i == Math.pow(unit,3)+Math.pow(decade,3)+Math.pow(hundreds,3)){
System.out.println("水仙花数:" + i); }
} } }

实验结果:

2. 编写Java程序,求13-23+33-43+…+973-983+993-1003的值。

实验源码:

public class number2 {
public static void main(String[] args) {
int sum=0,i=13,j=23;
while(i<=1003) {
sum +=(i-j);
i=i+20;
j=j+20;
}
System.out.println(sum);
}
}

实验结果:

3. 编程求1!+2!+3!+…+20!。

实验源码:

package Sum;

public class Sum {

    public static void main(String[] args) {
// TODO Auto-generated method stub
long And = 1;
long total = 0;
int i;
for(i = 1;i <= 20;i++) {
And *= i;
total += And;
}
System.out.println("1到20的阶乘之和为:" + total);
} }

实验结果:

4. 编写Java程序,计算8+88+888+…前10项之和。

实验源码:

public class number4 {
public static void main (String[] args){
int i;
long number = 0;
long result = 0;
System.out.println("计算8+88+888...前10项之和");
for(i=1; i<=10; i++){
number = number*10+8;
result+=number;
}
System.out.print(result);
}
}

实验结果:

5. 一个数如果恰好等于它的因子之和,这个数就称为完数。编写程序输出1000以内的所有完数

实验源码:

实验结果:

6. 编写应用程序,输出满足1+2+3+…+n<8888的最大正整数。

实验源码:

package demo;

public class demo {

    public static void main(String[] args) {
// TODO Auto-generated method stub
int n=0,sum=0;
while(sum<8888) {
n = n+1;
sum = sum+n;
}
System.out.println(n);
} }

实验结果:

7. 使用for循环打印下面的图形。

实验源码:

public class number7  {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int k = 1; k <=5-i; k++) {
System.out.print(" ");
}
for (int j = 1; j <= i*2-1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}

实验结果:

最新文章

  1. coreData部分报错:This NSPersistentStoreCoordinator has no persistent stores.
  2. alloc &amp;&amp; afree
  3. JavaScript的一些认识
  4. Sco Openserver下 配置SSH服务(图解)
  5. web系统之session劫持解决
  6. 组合模式(Composite Pattern)
  7. IOS 可靠性测试 iosMonkey
  8. jQuery 操作 input 之 checkbox
  9. Python内置函数(25)——getattr
  10. C# 换行
  11. C# 算法之链表、双向链表以及正向反向遍历实现
  12. TiDB 部署及数据同步
  13. 单词搜索 II &#183; Word Search II
  14. HDU 1102 Constructing Roads(kruskal)
  15. Angular.js-2入门
  16. Python_selenium之获取当前页面的href属性,id属性,图片信息和截全屏
  17. 15 GIL 全局解释器锁 C语言解决 top ps
  18. Oracle 同环比排除分母0
  19. Node.js 调用 restful webservice
  20. laravel 导出插件

热门文章

  1. 前端css知识实现自动打字,文字滚动
  2. 【SQL-历史执行语句查询】 查询对数据库执行了哪些SQL
  3. 基于ElementUI封装可复用的表格组件
  4. MFC 画字体DrawText()或TextOut(),CFont字体样式类
  5. 通俗理解数字签名,ssl数字证书和https
  6. [Luogu] 花神游历各国
  7. [python]@cached_property缓存装饰器
  8. Linux网络编程五、套接字超时
  9. javascript数组的增删改和查询
  10. elasticsearch-head后台运行