数据结构(Java语言版)实验答案.docxVIP

  • 3
  • 0
  • 约4.83万字
  • 约 40页
  • 2023-09-16 发布于澳门
  • 举报
PAGE 2 绪论实验答案 class Solution //存放解 { int cnt; //根个数 double x1; //根1 double x2; //根2 } public class 实验1_2 { static Solution solve(double a, double b, double c) //求方程的根 { Solution s = new Solution(); double d = b * b - 4 * a * c; if (d 0) t = 0; else if (Math.abs(d) = 0.0001) //等于0 { t = 1; s.x1 = (-b + Math.sqrt(d)) / (2 * a); } else { t = 2; s.x1 = (-b + Math.sqrt(d)) / (2 * a); s.x2 = (-b - Math.sqrt(d)) / (2 * a); } return s; } static void disp(Solution s) //输出结果 { if (t == 0) System.out.println(无根); else if (t == 1) System.out.printf(一个根为%.1f\n, s.x1); else System.out.printf(两个根为%.1f和%.1f\n, s.x1, s.x2); } public static void main(String[] args) { Solution s; double a = 2, b = -3, c = 4; System.out.printf(\n 测试1\n); System.out.printf( a=%.1f, b=%.1f, c=%.1f , a, b, c); s = solve(a, b, c); disp(s); a = 1; b = -2; c = 1; System.out.printf(\n 测试2\n); System.out.printf( a=%.1f, b=%.1f, c=%.1f , a, b, c); s = solve(a, b, c); disp(s); a = 2; b = -1; c = -1; System.out.printf(\n 测试3\n); System.out.printf( a=%.1f, b=%.1f, c=%.1f , a, b, c); s = solve(a, b, c); disp(s); } } 《数据结构(Java)》实验(项目)指导书 线性表实验 class Stud { int no; //学号 String name; //姓名 String course; //课程 int fraction; //分数 public Stud(int no1, String name1, String course1, int fraction1) //构造方法 { no = no1; name = name1; course = course1; fraction = frac

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档