java程序设计实验 告怎么写,实验 告三

实验题1:调试Math类应用程序并记录运行结果

题目要求】

步骤1:进入Eclipse软件;

步骤2:录入本实验程序源代码如下,并调试运行;

publicclass TestEx301 {

public static void main(String[] args) {

double a = Math.random(); // 得到一个随机数a

double b = Math.random(); // 得到一个随机数b

System.out.println(Math.pow(a, 8)); // 得到a的8次幂

System.out.println(Math.round(b)); // 得到返回最接近b的long类型的值

System.out.println(Math.log(Math.pow(Math.E, 5))); // 先得到e的5次幂,再返回(底数是e)double 值的自然对数

double d = 60.0, r = Math.PI / 4;

System.out.println(Math.toRadians(d)); // 返回弧度值

System.out.println(Math.toDegrees(r)); // 返回角度值

}

}

步骤3:阅读理解实验注释,并记录实验结果;

步骤4:完成实验 告。

【实验过程记录】

.运行结果(抓屏)

3.如果将StringBuffer类换成String类,运行结果将如何/p>

【实验总结和收获】

实验题3:练习并调试String类的使用

【题目要求】

调试并实现一个字符串排序的简单算法。

算法说明:

(1)定义字符串数组存储给定字符串;

(2)运用冒泡排序法,在内层循环中用String类的compareTo( )方法对字符串进行比较;

(3)循环输出按字典顺序排序好的字符串。

//实验源程序:

public class TestEx303{

public static void main(String args[]) {

String a[] = { “desk”, “apple”, “Applet”, “hotgirl”, “coolboy” };

for (int i = 0; i < a.length – 1; i++) {

for (int j = i + 1; j < a.length; j++) {

if (a[j].compareTo(a[i]) < 0) {

String temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

for(int i=0;i

System.out.println(a[i]);

}

}

}

【实验过程记录】

1.运行中出现的问题与解决方案

2.运行后结果(抓图)

[程序2源程序及运行结果(抓图)]

[程序4源程序及运行结果(抓图)]

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览91961 人正在系统学习中 相关资源:国标软件设计文档(操作手册(GB8567——88),测试分析 告(GB8567…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年2月10日
下一篇 2021年2月10日

相关推荐