3)System.out.print("wrong number of poin。一 Java博客作业( 六 )。" />

一 Java博客作业( 六 )

< 3)System.out.print("wrong number of points");String[] point2 = dj[1].split(",");String[] point3 = dj[2].split(",");if (point1.length == 2 && point2.length == 2 && point3.length == 2) {if (legal(point1[0]) && legal(point1[1]) && legal(point2[0]) && legal(point2[1]) && legal(point3[0])&& legal(point3[1])) {double x0 = Double.parseDouble(point1[0]);double y0 = Double.parseDouble(point1[1]);double x1 = Double.parseDouble(point2[0]);double y1 = Double.parseDouble(point2[1]);double x2 = Double.parseDouble(point3[0]);double y2 = Double.parseDouble(point3[1]);double a = Math.sqrt(Math.pow(y1 - y0, 2) + Math.pow(x1 - x0, 2));double b = Math.sqrt(Math.pow(y2 - y0, 2) + Math.pow(x2 - x0, 2));double c = Math.sqrt(Math.pow(y2 - y1, 2) + Math.pow(x2 - x1, 2));if (dj.length == 3 && a + b > c && a + c > b && b + c > a) {if (a*a + b*b < c*c||c*c+ b*b< a*a|| a*a +c*c < b*b)System.out.print("true false false");if (a*a + b*b ==c*c||c*c+ b*b==a*a|| a*a +c*c==b*b)//点14System.out.print("false true false");if (a*a + b*b >c*c&&c*c+ b*b> a*a&& a*a +c*c > b*b)System.out.print("false false true");} elseSystem.out.print("data error");if (dj.length > 3)System.out.print("wrong number of points");} elseSystem.out.print("Wrong Format");} elseSystem.out.print("Wrong Format");}void Four(String x) {String[] dj = x.split(" ");String[] point1 = dj[0].split(",");if (dj.length < 5)System.out.print("wrong number of points");String[] point2 = dj[1].split(",");String[] point3 = dj[2].split(",");String[] point4 = dj[3].split(",");String[] point5 = dj[4].split(",");if (!dj[1].equals(dj[0])) {if (point1.length == 2 && point2.length == 2 && point3.length == 2) {if (legal(point1[0]) && legal(point1[1]) && legal(point2[0]) && legal(point2[1]) && legal(point3[0])&& legal(point3[1]) && legal(point4[0]) && legal(point4[1]) && legal(point5[0])&& legal(point5[1])) {double x0 = Double.parseDouble(point1[0]);double y0 = Double.parseDouble(point1[1]);double x1 = Double.parseDouble(point2[0]);double y1 = Double.parseDouble(point2[1]);double x2 = Double.parseDouble(point3[0]);double y2 = Double.parseDouble(point3[1]);double x3 = Double.parseDouble(point4[0]);double y3 = Double.parseDouble(point4[1]);double x4 = Double.parseDouble(point5[0]);double y4 = Double.parseDouble(point5[1]);double a = Math.sqrt(Math.pow(y2 - y4, 2) + Math.pow(x2 - x4, 2));double b = Math.sqrt(Math.pow(y3 - y2, 2) + Math.pow(x3 - x2, 2));double c = Math.sqrt(Math.pow(y4 - y3, 2) + Math.pow(x4 - x3, 2));if (dj.length == 5 && a + b > c && a + c > b && b + c > a) {} elseSystem.out.print("data error");if (dj.length > 5)System.out.print("wrong number of points");} elseSystem.out.print("Wrong Format");} elseSystem.out.print("Wrong Format");} elseSystem.out.print("points coincide");}void Five(String x){} }View Cod
三、踩坑心得 1、第一次大作业
了解了数据类型转换,有自动类型转换和强制类型转换,容量小的可以往容量大的转换(隐式),但容量大的往容量小的转换则需要强制转换(显式)
float k =(float) (kg / 0.45359237);float m =(float)(meter / 0.0254);
当把任何基本类型和字符串值进行连接运算时,基本类型会被自动转成字符串类型,连接字符串,第二题要求找到奇数并输出,这样操作非常简单
String sum=""; if(a%2!=0)sum+=a;
字符串相关函数非常好用,如分割字符串(),()
有时计算机计算会出现一小点误差,我们避免用'=='而用Math.abs( - )< 0.00001或许会得到想要的答案
2、第二次大作业
类里的和很好用,可以帮助判断字符,()可以对字符串里的每位进行判断操作,非常方便
获取输入时,要注意()方法返回的是Enter键之前的所有字符,它可以得到带空格的字符串的 。而next()会自动消去有效字符前的空格,只返回输入的字符,不能得到带空格的字符串
s.close()是一个好习惯 。
3、第三次大作业
正则表达式的使用仍处于初级阶段,还需要认真学习