




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
用java求三角形的周长和面积 用java求三角形的周长和面积?public class Js private double a; private double b; private double c; Js(double a,double b,double c) this.a = a; this.b = b; this.c = c; public double getA() return a; public double getB() return b; public double getC() return c; public double area() double s1=(a+b+c)/2;double s2 = s1*(s1-a)*(s1-b)*(s1-c); double result = Math.sqrt(s2);return result; public double jsLength() return a+b+c; class Jxcomputer public static void main(String args) Js js = new Js(3,6,8); System.out.println("三角形三边长度分别为:"+"a:"+js.getA()+"tb:"+js.getB()+"tc:"+js.getC(); System.out.println("三角形面积为:"+js.area(); System.out.println("三角形周长为:"+js.jsLength(); 【编译与运行】 编译:javac Js.java 运行:java Jxcomputer 计算三角形的面积和周长./* (#)Point.java 2008-1-4*/package .robert.baidu.triangle;/* author R*/public class Point private int x;private int y;/* 构造函数*/public Point(int X, int Y) x=X;y=Y;public int getX() return x;public void setX(int x) this.x = x;public int getY() return y;public void setY(int y) this.y = y;/* (#)Triangle.java 2008-1-4*/package .robert.baidu.triangle;/* author R*/* 构造函数*/public class Triangle private Point a;private Point b;private Point c;public Triangle(Point A,Point B,Point C) a=A;b=B;c=C;/* 三条边的长度*/private double l1=Math.sqrt(Math.pow(a.getX()-b.getX(),2)+Math.pow(a.getY()-b.getY(), 2);private double l2=Math.sqrt(Math.pow(c.getX()-b.getX(),2)+Math.pow(c.getY()-b.getY(), 2);private double l3=Math.sqrt(Math.pow(a.getX()-c.getX(),2)+Math.pow(a.getY()-c.getY(), 2);/* 定义Heron公式*/private double heron(double x, double y, double z) double p=(x+y+z)/2; double area=Math.sqrt(p*(p-x)*(p-y)*(p-z); return area; /* 周长是三边之和*/public double getVolume()return l1+l2+l3; /* 调用海伦公式求面积*/public double getArea()return heron(l1,l2,l3);/* 三点不一线*/public boolean isTriangle()return (a.getX()-b.getX()/(a.getY()-b.getY()!=(a.getX()-c.getX()/(a.getY()-c.getY();#交谈中请勿轻信汇款、中奖信息、陌生电话,勿使用外挂软件。候雷(78665444) 13:16:31public class OODemol002 public static void main(String args) Container c = new Container();Thread t1 = new Thread(new Laundryman( c, 1);Thread t2 = new Thread(new Laundryman(c, 2);Thread t3 = new Thread(new WashingWorker(c, 1);Thread t4 = new Thread(new WashingWorker(c, 2);t1.start();t2.start();t3.start();t4.start();class Clothes int in;public Clothes(int index) this.in = index;class Container Clothes clothes = new Clothes6;int index = 0;public synchronized void push(Clothes c) while (index = clothes.length) try this.wait(); catch (InterruptedException e) / TODO Auto-generated catch blocke.printStackTrace();this.notify();clothesindex = c;index+;public synchronized Clothes pop() while (index = 0) try this.wait(); catch (InterruptedException e) / TODO Auto-generated catch blocke.printStackTrace();this.notify();index-;return clothesindex;/* 编写程序,使用多线程模拟实现洗衣房工作的示例。条件如下: 1. 洗衣工2人(对应2个线程) 2. 晾衣工2人 3. 共50件衣服 4.* 洗衣工每2秒洗1件衣服 5. 晾衣工每1秒晾1件衣服*/class Laundryman implements Runnable Container container;int id;public Laundryman(Container container, int id) / TODO Auto-generated method stubthis.container = container;this.id = id;public void run() / TODO Auto-generated method stubClothes c = null;try for (int i = 0; i < 25; i+) Thread.sleep(2000);c = new Clothes(i);System.out.println("洗衣工" + id + "洗了衣服:" + c.in);container.push(c); catch (InterruptedException e) / TODO Auto-generated catch blocke.printStackTrace();class WashingWorker implements Runnable Container container;int id;public WashingWorker(Container container, int id) this.container = container;this.id = id;public void run() / TODO Auto-generated method stubfor (int i = 0; i < 25; i+) Clothes c =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年服务创新试题及答案
- 2025年油墨业务员考试试题及答案
- 编程逻辑试题及答案
- 院感竞赛试题环境表面清洁与消毒管理规范试题(附答案)
- 物业 知识试题及答案
- 教师招聘之《幼儿教师招聘》强化训练题型汇编含答案详解【综合题】
- 智能组网试题及答案
- 深度研究:2025年K2教育人工智能个性化学习系统在优化教学过程中的应用报告
- 2025二手房购房合同简化范本
- 2025石油买卖购销合同
- 《销售培训实例》课件
- 象棋入门课件教学
- 2024年3dmax模型制作与精修培训课件
- 咨询类合同合同范例
- Vue3系统入门与项目实战
- 旅游产品开发与设计作业指导书
- 中职语文职业模块1.2《宁夏闽宁镇:昔日干沙滩-今日金沙滩》教案
- 3.2 摩擦力 课件 高一上学期物理人教版(2019)必修第一册
- 水土保持工程概(估)算编制规定
- DZ/T 0430-2023 固体矿产资源储量核实报告编写规范(正式版)
- 2024年海南省中职教师技能大赛-新能源汽车维修 赛项规程
评论
0/150
提交评论