栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

本科课程【java程序设计】实验1 - 循环结构程序设计

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

本科课程【java程序设计】实验1 - 循环结构程序设计

大家好,我是【1+1=王】, 热爱java的计算机(人工智能)渣硕研究生在读。
如果你也对java、人工智能等技术感兴趣,欢迎关注,抱团交流进大厂!!!
Good better best, never let it rest, until good is better, and better best.

近期会把自己本科阶段的一些课程设计、实验报告等分享出来,供大家参考,希望对大家有帮助。

博客更新至专栏【课程设计实验报告】:https://blog.csdn.net/weixin_43598687/category_11640051.html

一、 实验目的

1、掌握逻辑运算符的使用方法。
2、掌握利用for语句、while语句、do while语句实现选择结构程序设计的方法。
3、掌握break,continue在循环语句中的作用。

二、 实验内容 1. 实验任务

1).编写应用程序求1!+2!+…+10!。
2) .编写一个应用程序求100以内的全部素数。
3) .分别用do-while和for循环计算1+1/2!+1/3!+1/4!… … 的前20项和。
4).编程找出1000之内的所有完数,并按下面格式输出其因子:
6 its factors are 1,2,3.。
5).编写应用程序,使用for循环语句计算8+88+888…前10项之和。
6).编写应用程序,输出满足1+2+3…+n<8888的最大正整数n。
7). 编写一程序,输出从100到1000包含数字5的全部偶数。

2. 程序设计
int n=10;
int temp=1,sum=0;
for(int i=1;i<=n;i++) {
	temp = temp*i;
	sum+=temp;
}
System.out.println(n+"的阶层和="+sum);
int n=100,j ;
System.out.print("100以内的素数有:");
int n=100,j ;
System.out.print("100以内的素数有:");
for(int i=2;ii/2) {System.out.print(i+",");}
}
double sum1=0,sum2=0,temp=1;
int i;
for(i=1;i<=20;i++) {
	temp = temp*i;
	sum1+=(1/temp);
}
i=1;temp=1;
while(i<=20) {
	temp = temp*i;
	sum2+=(1/temp);
	i++;
}
		 
System.out.println("for循环前二十项和为:"+sum1);
System.out.println("while循环前二十项和为:"+sum2);
int n = 1000,sum=0,temp;
int yinzi[] = new int[500];
System.out.println("1000以内的完数有:");
for(int i=1;i 
Long sum=0L,temp=8L;
for(int i=0;i<10;i++) {
 sum+=temp;
 temp=temp*10+8;
}
System.out.println("8+88+888+...的前十项和为:"+sum);
int sum=0,max=8888,i=1;
 while(true) {
	 sum+=i;
	 if(sum>=max) {
		 break;
	 }
	 i++;
 }
System.out.println("小于8888的最大n为:"+(i-1));
int i,yushu,count;
 System.out.println("100到1000包含数字5的全部偶数为:");
 for(i=100;i<1000;i+=2) {
	 count = i/10;
	 while(count!=0) {
		 if(count%10==5) {
			 System.out.print(i+",");
		 }
		 count/=10;
	 }
 }
3. 实验结果

三、 实验环境
  1. 操作系统:WINDOWS 10
  2. 开发工具:JDK 1.8 、 Eclipse
  3. 实验设备:PC
总结

每种循环有着类似的地方,但也有着些许不同,使用的条件也不尽相同,需要看设定的条件来较好的选择循环。确定循环体和循环条件,循环结构就确定了,可选用c语言提供的三种循环语句(for,while,do-whlie)实现循环;
在使用循环的时候比较混乱,不知道什么情况下运用哪种循环,可能是刚学的原因,希望过段时间能够把这三种循环理解好,并较好的运用。

博客更新至专栏【课程设计实验报告】:https://blog.csdn.net/weixin_43598687/category_11640051.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/845699.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号