云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java实验报告三模板

Java实验报告三模板

  • 62 次阅读
  • 3 次下载
  • 2025/6/13 23:43:09

}

}

}

case 1:System.out.printf(\); break;

case 5:System.out.printf(\); break;

case 10:System.out.printf(\); break;

default:System.out.printf(\);

5、public class six {

public static void main(String[] args) {

// TODO Auto-generated method stub int sum=0,i=1;

for( i=1;i<=100;i++){ if(i%3==0){

sum=sum+i;

} }

System.out.println(\到100之间能够被3整除的整数和为:\+sum); do{

if(i%3==0){ }

i++;

}while(i<=100);

System.out.println(\到100之间能够被3整除的整数和为:\+sum); while(i<=100){ if(i%3==0){

sum=sum+i;

} i++; }

System.out.println(\到100之间能够被3整除的整数和为:\+sum); }

6、public class seven {

public static void main(String[] args) {

// TODO Auto-generated method stub }

sum=sum+i;

double sum =0;

for(int i=1;i<=20;i++){ double n=1.0;

for(int j=1;j<=i;j++){ n=n*j; }

sum=sum+1/n; }

System.out.printf(\结果为:\+sum); }

7、public class eight { }

8、public class nine {

public static void main(String[] args) {

// TODO Auto-generated method stub Set sets = new HashSet(); sets.add(1.0); // 添加第一个元素 1 int i,j=2;

for(i=2;Math.pow(i, j)<=10000;i++){ for(j=2;Math.pow(i, j)<=10000;j++){ sets.add(Math.pow(i, j)); }

public static void main(String[] args) { }

// TODO Auto-generated method stub int a[]=new int[10]; int sum=0;

for(int i=0;i<10;i++){ }

System.out.println(\请输入一个整数:\); Scanner reader=new Scanner(System.in); int num=reader.nextInt(); a[5]=num;

for(int i=0;i<10;i++) { System.out.println(a[i]); sum=sum+a[i]; }

System.out.print(\数组之和为:\+sum);

a[i]=i+1;

}

}

}

j = 2; }

System.out.println(10000-sets.size());

4.实验总结

设计题一中需要将double型改变为int型,知识点为强制类型转换;设计题二和四中知识点为switch分支;在设计题五中3个循环for,do..while,while的使用中要注意循环条件;在设计题六中需要求阶层,注意“1”的位置——应该在第一层循环内,二层循环外;实验题七中知识点为数组的定义,注意数组下标是以0开头的,循环输出时可以采用简单方法(for int i :a);最后一题中需要去掉次方数,但是有些数字在不同的次方中同时出现,不知道应该怎么舍去重复的,而且需要运用的知识点不怎么熟悉。

附录: 实验1 托运行李

模板代码

BaggageAndMony.java

import java.util.Scanner; public class BaggageAndMony {

public static void main(String[] args) {

int trainCharge=12; int carCharge=22; double planeCharge=0.062;

Scanner reader=new Scanner(System.in); double weight,charge;

System.out.printf(\输入行李重量:\weight=reader.nextDouble();

System.out.printf(\行李重量:%f公斤(kg)\\n\System.out.printf(\需要计费的重量:%d(kg)\\n\

charge=(int)weight*trainCharge; //将表达式(int)weight*trainCharge赋值给charge

System.out.printf(\用火车托运(%d元/kg),费用%f元\\n\System.out.printf(\需要计费的重量:%d(kg)\\n\

charge=(int)(weight+0.5)*carCharge; //将表达式(int)(weight+0.5)*carCharge赋值给

charge

System.out.printf(\用汽车托运(%d元/kg),费用%f元\\n\ System.out.printf(\行李重量:%f克(g)\\n\

System.out.printf(\需要计费的重量:%d(g)\\n\

charge=(int)(weight*1000+0.5)*planeCharge; //将表达(int)(weight*1000+0.5)*planeCharge赋值给charge

System.out.printf(\用飞机托运(%f元/kg),费用%f元\\n\ }

}

实验2 自动售货机

模板代码 MachineSell.java

import java.util.Scanner; public class MachineSell {

public static void main(String[] args) { int money; int drinking;

System.out.printf(\投入金额:2或3元(按Enter键确认):\ Scanner reader=new Scanner(System.in); money=reader.nextInt(); if(money==2){ System.out.printf(\选择净净矿泉水(1),甜甜矿泉水(2),和美美矿泉水(3)之一:\\n\ System.out.printf(\输入1,2或3:\ drinking=reader.nextInt(); switch(drinking){ case 1:System.out.printf(\得到净净矿泉水\\n\ break;

case 2:System.out.printf(\得到甜甜矿泉水\\n\ break;

case 3:System.out.printf(\得到美美矿泉水\\n\ break;

default:System.out.printf(\选择错误\

}

搜索更多关于: Java实验报告三模板 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} } } case 1:System.out.printf(\); break; case 5:System.out.printf(\); break; case 10:System.out.printf(\); break; default:System.out.printf(\); 5、public class six { public static void main(String[] args) { // TODO Auto-generated method stub int sum=0,i=1; for( i=1;i<=100;i++){

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com