欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    华工Java语言程序设计作业答案1-.doc

    • 资源ID:53961523       资源大小:215.51KB        全文页数:14页
    • 资源格式: DOC        下载积分:11.9金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要11.9金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    华工Java语言程序设计作业答案1-.doc

    华南理工大学学生实验报告书实验名称java课程实验课程名称Java语言程序设计课程号学院软件学院专业软件工程班级学生姓名*学号*实验地点实验日期第一章1.3public class Exe1_3 public static void main(String args) System.out.println(" J A V V A"); System.out.println(" J A A V V A A"); System.out.println("J J AAAAA V V AAAAA"); System.out.println(" J J A A V A A"); 第二章2.21import java.util.Scanner;public class Exe2_21 public static void main(String args) System.out.println("Enter three points for triangle : "); Scanner input = new Scanner(System.in); double x1 = input.nextDouble(); double y1 = input.nextDouble(); double x2 = input.nextDouble(); double y2 = input.nextDouble(); double x3 = input.nextDouble(); double y3 = input.nextDouble(); double side1 = Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ); double side2 = Math.sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) ); double side3 = Math.sqrt( (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) ); double s = (side1 + side2 + side3) / 2; double area = Math.sqrt( s * (s-side1) * (s-side2) * (s-side3) ); System.out.println("The area of the triangle is " + area); 第三章3.27import java.util.Scanner;public class Exe3_27 public static void main(String args)final double x1 = 0;final double y1 = 0;final double x2 = 200;final double y2 = 0;final double x3 = 0;final double y3 = 100;Scanner input = new Scanner(System.in);System.out.println("Enter a point's x- and y-coordinates : ");double x = input.nextDouble();double y = input.nextDouble();double y_x = -(x/2) + 100;if( x<x1 && x<x3 )System.out.println("The point is not in the triangle!");else if( y<y1 && y<y2 )System.out.println("The point is not in the triangle!");else if( y>y_x )System.out.println("The point is not in the triangle!");elseSystem.out.println("The point is in the triangle!"); 3.29import java.util.Scanner;public class Exe3_29 public static void main(String args)Scanner input = new Scanner(System.in);System.out.println("Enter circle1's center x- ,y-coordinates and radius : ");double x1 = input.nextDouble();double y1 = input.nextDouble();double r1 = input.nextDouble();System.out.println("Enter circle2's center x- ,y-coordinates and radius : ");double x2 = input.nextDouble();double y2 = input.nextDouble();double r2 = input.nextDouble();double length = Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );double L1 = Math.abs( r1 - r2 );double L2 = r1 + r2;if(length <= L1)System.out.println("circle2 is in circle1!");else if(length <= L2)System.out.println("circle2 overlaps circle1!");elseSystem.out.println("circle2 does not overlap circle1");第四章4.25public class Exe4_25 public static void main(String args)double PI = 0,sum = 0;int i, n;for( i = 10000; i <= 100000; i += 10000 )for( n = 1; n < i; n += 2 )sum += (1.0/(2*n-1) - 1.0/(2*n+1);PI = 4 * sum;System.out.println("i = " + i + " and 兀 = " + PI );sum = 0;4.41import java.util.Scanner;public class Exe4_41 public static void main(String args)System.out.println("Enter numbers : ");Scanner input = new Scanner(System.in);int integer,max,count;integer = input.nextInt();max = integer;count = 1;while(integer != 0)integer = input.nextInt();if(integer > max)max = integer;count = 1;else if(integer < max)elsecount+=1;System.out.println("The largest number is " + max);System.out.println("The occurence count of the largest number is " + count);第五章5.21import java.util.Scanner;public class Exe5_21 public static void main(String args)Scanner input = new Scanner(System.in);double ary = new double10;System.out.println("Enter ten numbers : ");for (int i = 0; i < ary.length; i+ )aryi = input.nextDouble();double sum = 0, sum_pow = 0;for (int i = 0; i < ary.length; i+)sum += aryi;for (int i = 0; i < ary.length; i+)sum_pow += aryi*aryi;double mean = sum/ary.length;double standard_value = Math.sqrt(sum_pow - sum*sum/ary.length) / (ary.length - 1.0) );System.out.println("The mean is " + mean);System.out.println("The standard deviation is " + standard_value);第六章6.18import java.util.Scanner;public class Exe6_18 public static void main (String args) System.out.print("Enter ten real number : "); double array = new double10; Input(array); Sort(array); Output(array); /输入 public static void Input(doubleary) Scanner input = new Scanner(System.in); for(int i = 0; i < ary.length; i+) aryi = input.nextDouble(); /输出 public static void Output(doubleary) for(int i = 0; i < ary.length; i+) System.out.print(" " + aryi); /冒泡排序 public static void Sort(doubleary) int n = 0;boolean work = true; double temp = 0; for(int i = 1; i < ary.length; i+) work = true; for( n = 0; n < ary.length-i; n+) if (aryn > aryn+1) temp = aryn; aryn = aryn+1; aryn+1 = temp; work = false; if(work) break; 第七章7.6import java.util.Scanner;public class Exe7_6 final static int R = 3;final static int L = 3; public static void main(Stringargs) double matrix1 = new doubleLR; double matrix2 = new doubleLR; System.out.println("Enter matrix1 : "); Input(matrix1); System.out.println("Enter matrix2 : "); Input(matrix2); Output(matrix1,matrix2,multiplyMatrix(matrix1,matrix2); /输入 public static void Input(doublematrix) Scanner input = new Scanner(System.in); for(int line = 0; line < L; line+) for(int row = 0; row < R; row+) matrixlinerow = input.nextDouble(); /输出 public static void Output(double a, double b,doublematrix) int n = 0; for(int i = 0; i < L; i+ ) if( i != 1) for( n = 0; n < R; n+) System.out.print(" " + ain); System.out.print(" "); for( n = 0; n < R; n+) System.out.print(" " + bin); System.out.print(" "); for( n = 0; n < R; n+) System.out.print(" " + matrixin); else for( n = 0; n < R; n+) System.out.print(" " + ain); System.out.print(" *"); for( n = 0; n < R; n+) System.out.print(" " + bin); System.out.print(" ="); for( n = 0; n < R; n+) System.out.print(" " + matrixin); System.out.println(); /矩阵相乘 public static double multiplyMatrix(double a, double b) double c = new doubleLR; for(int i = 0; i < L; i+) for(int j = 0; j < R; j+) cij = 0; for(int k = 0; k < R; k+) cij += aik*bkj; /cij = ai0*b0j + ai1*b1j + ai2*b2j; return c; 第八章8.12import java.util.Scanner;public class Exe8_12public static void main(String args)Scanner input = new Scanner(System.in);System.out.print("Enter the endpoints of the first line segment : "); double x1=input.nextDouble(); double y1=input.nextDouble(); double x2=input.nextDouble(); double y2=input.nextDouble(); System.out.print("Enter the endpoints of the second line segment : "); double x3=input.nextDouble(); double y3=input.nextDouble(); double x4=input.nextDouble(); double y4=input.nextDouble(); double a,b,c,d,e,f; a=y2-y1; b=x1-x2; c=y4-y3; d=x3-x4; e=(y2-y1)*x1+(x1-x2)*y1; f=(y4-y3)*x3+(x3-x4)*y3; LinearEquation inter=new LinearEquation(a,b,c,d,e,f); if(inter.isSolvable() System.out.print("The intersecting point is:"+inter.getX()+","+inter.getY(); else System.out.print("NULL"); class LinearEquationprivate double a;private double b;private double c;private double d;private double e;private double f;public LinearEquation(double a,double b,double c,double d,double e,double f)this.a = a;this.b = b;this.c = c;this.d = d;this.e = e;this.f = f;boolean isSolvable()if (a * d - b * c != 0)return true;elsereturn false;double getX() return (e * d - b * f) / (a * d - b * c); double getY() return (a * f - e * c) / (a * d - b * c); 8.13import java.util.Scanner;public class Exe8_13 public static void main(String args) Scanner input = new Scanner(System.in); System.out.println("Enter the number of rows and columns of the array : "); int row = input.nextInt(); int column = input.nextInt(); double array = new doublerowcolumn; System.out.println("Enter the array : "); for(int i = 0; i < row; i+) for(int n = 0; n < column; n+) arrayin = input.nextDouble(); System.out.println("The location of the largest element is " + locateLargest(array).maxValue + " at (" + locateLargest(array).row + "," + locateLargest(array).column + ")"); public static Location locateLargest(double a)double maxNumber=a00;int row=0,column=0;for(int i=0;i<a.length;i+)for(int j=0;j<a0.length;j+)if(aij>maxNumber)maxNumber=aij;row=i;column=j;return new Location(row,column,maxNumber);class LocationLocation(int row,int column,double maxValue)this.row=row;this.column=column;this.maxValue=maxValue;public int row,column;public double maxValue;

    注意事项

    本文(华工Java语言程序设计作业答案1-.doc)为本站会员(wuy****n92)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开