2条回答 默认 最新
关注 只给你代码,实验结论你要自己写哈,另外记得采纳哈。
第一个学生的实验
import java.text.MessageFormat; public class Student { private String sno; private String sname; private int age; private String address; private String tel; public Student(String sno, String sname, int age, String address, String tel) { this.sno = sno; this.sname = sname; this.age = age; this.address = address; this.tel = tel; } public void study() { System.out.println(MessageFormat.format("{0}学习ing...", this)); } public void eat() { System.out.println(MessageFormat.format("{0}吃饭ing...", this)); } public void sleep() { System.out.println(MessageFormat.format("{0}睡觉ing...", this)); } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public String toString() { return MessageFormat.format("学生(学号:{0}, 姓名:{1}, 年龄:{2}, 地址:{3}, 电话:{4})", sno, sname, age, address, tel); } public static void main(String[] args) { Student s1 = new Student("1", "张三", 20, "张三的地址", "张三的电话"); Student s2 = new Student("2", "李四", 20, "李四的地址", "李四的电话"); Student s3 = new Student("3", "王五", 20, "王五的地址", "王五的电话"); s1.study(); s1.eat(); s1.sleep(); s2.study(); s2.eat(); s2.sleep(); s3.study(); s3.eat(); s3.sleep(); } }
第二个斐波那契数列
import java.text.MessageFormat; public class Test { public static void main(String[] args) { int n = 15; System.out.println(MessageFormat.format("斐波那契数列第{0}个值为:{1}", n, getFibonacci(n))); } public static int getFibonacci(int n) { if (n <= 0) { throw new IllegalArgumentException(); } switch (n) { case 1: return 0; case 2: return 1; default: return getFibonacci(n - 1) + getFibonacci(n - 2); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 有偿四位数,节约算法和扫描算法
- ¥15 VUE项目怎么运行,系统打不开
- ¥50 pointpillars等目标检测算法怎么融合注意力机制
- ¥15 关于超局变量获取查询的问题
- ¥20 Vs code Mac系统 PHP Debug调试环境配置
- ¥60 大一项目课,微信小程序
- ¥15 求视频摘要youtube和ovp数据集
- ¥15 在启动roslaunch时出现如下问题
- ¥15 汇编语言实现加减法计算器的功能
- ¥20 关于多单片机模块化的一些问题