学习java总结
OO前三次作业总结
1.前言
题目集1的知识点:
Scanner的输入,以及java的简单输出;java的if-else选择分支结构;java的for循环结构;简单的数组排序。
题目集1的题量:
1.计算两个数的和;2.电话键盘字母数字转换;3.成绩分级管理;4.计算税率;5.计算钱币;6.使用一维数组求平均值;7.对多个整数进行排序;8.判断三角形类型。
题目集1的难度:
题目集1整体难度偏低,属于一些基础java知识,对于刚开始学java的我们而言很有帮助,可以加深我们的java基础。
题目集2的知识点:
数字字符串分割以及转换,找到字符串中的每个单个字符;简单的合并数组并排序,考察数组内部排序;考察方法的调用。
题目集2的题量:
1.IP地址转换;2.合并两个有序数组为新的有序数组;3.判断闰年及星期几;4.求下一天;5.求前N天。
题目集2的难度:
整体难度中等,大部分属于方法调用问题。
题目集3的知识点:
类的私有属性;类的封装性;正则表达式;BigInteger大数值。
题目集3的题量:
1.创建账户类Account;2.定义日期类;3.一元多项式求导(类设计)。
题目集3的难度:
题目集3的难度较之前两次难度加大,更难了,对于创建类以及定义类难度适中,但是一元多项式求导的难度很大,感觉写不出来,对于正则表达式理解的不够透彻。
2.设计与分析
针对于题目集1的7-8、题目集2的7-4、7-5以及题目集3的7-2、7-3做了以下的分析:
题目集1的7-8代码如下:
1 import java.util.Scanner; 2 public class Main { 3 public static void main(String[] args){ 4 Scanner input = new Scanner(System.in); 5 double x=input.nextDouble(); 6 double y=input.nextDouble(); 7 double z=input.nextDouble(); 8 9 if(!((x>=1.0)&&(x<=200.0)&&(200.0>=y)&&(y>=1.0)&&(200.0>=z)&&(z>=1.0))) 10 System.out.println("Wrong Format"); 11 else if(x+y<=z||x+z<=y||y+z<=x) 12 System.out.println("Not a triangle"); 13 else{ 14 if((x==y)&&(x==z)&&(y==z)) 15 { 16 System.out.println("Equilateral triangle"); 17 return; 18 } 19 if(((Math.abs(x*x+y*y-z*z)<=1e-6)||(Math.abs(y*y+z*z-x*x)<=1e-6)||(Math.abs(x*x+z*z-y*y)<=1e-6))&&((x==y)||(x==z)||(y==z))) 20 { 21 System.out.println("Isosceles right-angled triangle"); 22 return; 23 } 24 if(((x==y)||(x==z)||(y==z))) 25 { 26 System.out.println("Isosceles triangle"); 27 return; 28 } 29 if(((Math.abs(x*x+y*y-z*z)<=1e-6)||(Math.abs(y*y+z*z-x*x)<=1e-6)||(Math.abs(x*x+z*z-y*y)<=1e-6))) 30 { 31 System.out.println("Right-angled triangle"); 32 return; 33 } 34 else 35 { 36 System.out.println("General triangle"); 37 return; 38 } 39 } 40 } 41 }
由于只有一个类,过于简单,因此此处不放置类图进行介绍。
针对本题,根据题意使用double类型的浮点型数据进行输入,通过对三角形三条边x、y、z的判断来得到相应的结果,首先判断数据的合法性进行输出,再对三条边是否能组成三角形进行判断,之后判断是否为等边三角形、是否为等腰直角三角形、是否为等腰三角形、是否为直角三角形、或者为普通三角形。针对于这题而言,我感觉主要是考察学生对于if-else选择结构的调用、对Math类的调、数据边界校验。
题目集2的7-4代码如下:
1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Scanner scanner = new Scanner(System.in); 8 int year = scanner.nextInt(); 9 int month = scanner.nextInt(); 10 int day = scanner.nextInt(); 11 if(checkInputValidity(year,month,day)==true) 12 { 13 nextDate(year,month,day); 14 } 15 else 16 { 17 System.out.print("Wrong Format"); 18 } 19 } 20 public static boolean isLeapYear(int year) { 21 if(year%4==0&&year%100!=0||year%400==0) { 22 return true; 23 } 24 else { 25 return false; 26 } 27 28 29 } 30 public static boolean checkInputValidity(int year,int month,int day) { 31 if(year>=1820&&year<=2020&&month>0&&month<13&&day>0&&day<32) { 32 return true; 33 } 34 else { 35 return false; 36 } 37 38 39 } 40 public static void nextDate(int year,int month,int day) { 41 if(month==1||month==3|month==5||month==7||month==8||month==10||month==12) 42 { 43 if(day>=0&&day<=30) 44 { 45 day=day+1; 46 System.out.print("Next date is:"+year+"-"+month+"-"+day); 47 } 48 else if(day==31) 49 { 50 if(month==12) 51 { 52 year=year+1; 53 month=1; 54 day=1; 55 System.out.print("Next date is:"+year+"-"+month+"-"+day); 56 } 57 else 58 { 59 month=month+1; 60 day=1; 61 System.out.print("Next date is:"+year+"-"+month+"-"+day); 62 } 63 } 64 else 65 { 66 System.out.print("Wrong Format"); 67 } 68 } 69 else if(month==4||month==6|month==9||month==11) 70 { 71 if(day>=0&&day<=29) 72 { 73 day=day+1; 74 System.out.print("Next date is:"+year+"-"+month+"-"+day); 75 } 76 else if(day==30) 77 { 78 month=month+1; 79 day=1; 80 System.out.print("Next date is:"+year+"-"+month+"-"+day); 81 } 82 else 83 { 84 System.out.print("Wrong Format"); 85 } 86 } 87 else 88 { 89 if(isLeapYear(year)==true) 90 { 91 if(day>=0&&day<=28) 92 { 93 day=day+1; 94 System.out.print("Next date is:"+year+"-"+month+"-"+day); 95 } 96 else if(day==29) 97 { 98 month=month+1; 99 day=1; 100 System.out.print("Next date is:"+year+"-"+month+"-"+day); 101 } 102 else 103 { 104 System.out.print("Wrong Format"); 105 } 106 } 107 else 108 { 109 if(day>=0&&day<=27) 110 { 111 day=day+1; 112 System.out.print("Next date is:"+year+"-"+month+"-"+day); 113 } 114 else if(day==28) 115 { 116 month=month+1; 117 day=1; 118 System.out.print("Next date is:"+year+"-"+month+"-"+day); 119 } 120 else 121 { 122 System.out.print("Wrong Format"); 123 } 124 } 125 } 126 } 127 }
由于只有一个类,过于简单,因此此处不放置类图进行介绍。
针对于本题而言:求取下一天主要是先输入相应的年月日,通过调用方法判断输入日期是否合法,返回布尔值;通过此布尔值来判断if-else的选择结构,若不合法直接输出Wrong Format,反之调用nextDate方法对年月日三个数据进行判断输入下一天,不过在进行判断的时候需要注意平年以及闰年,注意跨年的数据。本题主要是为了考察学生对于方法的调用,灵活的在一个类内调用方法实现功能。
题目集2的7-5代码如下:
1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Scanner scanner = new Scanner(System.in); 8 int year = scanner.nextInt(); 9 int month = scanner.nextInt(); 10 int day = scanner.nextInt(); 11 int n = scanner.nextInt(); 12 if(checkInputValidity(year,month,day)==true) 13 {String a=""; 14 if(n<0) { 15 for(int i=0;i>n;i--) { 16 a=nextDate(year,month,day); 17 if(a.equals("Wrong Format")) { 18 break; 19 } 20 else { 21 String b[]=a.split("\\s+"); 22 year=Integer.parseInt(b[0]); 23 month=Integer.parseInt(b[1]); 24 day=Integer.parseInt(b[2]); 25 } 26 } 27 if(a.equals("Wrong Format")) { 28 System.out.print(a); 29 } 30 else { 31 System.out.print(n+" days ago is:"+year+"-"+month+"-"+day); 32 } 33 } 34 else { 35 for(int i=0;i<n;i++) { 36 a=lastDate(year,month,day); 37 if(a.equals("Wrong Format")) { 38 break; 39 } 40 else { 41 String b[]=a.split("\\s+"); 42 year=Integer.parseInt(b[0]); 43 month=Integer.parseInt(b[1]); 44 day=Integer.parseInt(b[2]); 45 } 46 } 47 if(a.equals("Wrong Format")) { 48 System.out.print(a); 49 } 50 else { 51 System.out.print(n+" days ago is:"+year+"-"+month+"-"+day); 52 } 53 } 54 55 } 56 else 57 { 58 System.out.print("Wrong Format"); 59 } 60 } 61 public static boolean isLeapYear(int year) { 62 if(year%4==0&&year%100!=0||year%400==0) { 63 return true; 64 } 65 else { 66 return false; 67 } 68 69 70 } 71 public static boolean checkInputValidity(int year,int month,int day) { 72 if(year>=1820&&year<=2020&&month>0&&month<13&&day>0&&day<32) { 73 if(month==1||month==3|month==5||month==7||month==8||month==10||month==12) { 74 if(day>=1&&day<=31) { 75 return true; 76 } 77 else { 78 return false; 79 } 80 } 81 else if(month==4||month==6|month==9||month==11) { 82 if(day>=1&&day<=30) { 83 return true; 84 } 85 else { 86 return false; 87 } 88 } 89 else { 90 if(isLeapYear(year)==true) { 91 if(day>=1&&day<=29) { 92 return true; 93 } 94 else { 95 return false; 96 } 97 } 98 else { 99 if(day>=1&&day<=28) { 100 return true; 101 } 102 else { 103 return false; 104 } 105 } 106 107 } 108 } 109 else { 110 return false; 111 } 112 113 114 } 115 public static String nextDate(int year,int month,int day) { 116 String a=""; 117 if(month==1||month==3|month==5||month==7||month==8||month==10||month==12) 118 { 119 if(day>=0&&day<=30) 120 { 121 day=day+1; 122 a=year+" "+month+" "+day; 123 } 124 else if(day==31) 125 { 126 if(month==12) 127 { 128 year=year+1; 129 month=1; 130 day=1; 131 a=year+" "+month+" "+day; 132 } 133 else 134 { 135 month=month+1; 136 day=1; 137 a=year+" "+month+" "+day; 138 } 139 } 140 else 141 { 142 a="Wrong Format"; 143 } 144 } 145 else if(month==4||month==6|month==9||month==11) 146 { 147 if(day>=0&&day<=29) 148 { 149 day=day+1; 150 a=year+" "+month+" "+day; 151 } 152 else if(day==30) 153 { 154 month=month+1; 155 day=1; 156 a=year+" "+month+" "+day; 157 } 158 else 159 { 160 a="Wrong Format"; 161 } 162 } 163 else 164 { 165 if(isLeapYear(year)==true) 166 { 167 if(day>=0&&day<=28) 168 { 169 day=day+1; 170 a=year+" "+month+" "+day; 171 } 172 else if(day==29) 173 { 174 month=month+1; 175 day=1; 176 a=year+" "+month+" "+day; 177 } 178 else 179 { 180 a="Wrong Format"; 181 } 182 } 183 else 184 { 185 if(day>=0&&day<=27) 186 { 187 day=day+1; 188 a=year+" "+month+" "+day; 189 } 190 else if(day==28) 191 { 192 month=month+1; 193 day=1; 194 a=year+" "+month+" "+day; 195 } 196 else 197 { 198 a="Wrong Format"; 199 } 200 } 201 } 202 return a; 203 } 204 public static String lastDate(int year,int month,int day) { 205 String a=""; 206 if(month==2||month==4|month==6||month==8||month==9||month==11) 207 { 208 if(day>1) 209 { 210 day=day-1; 211 a=year+" "+month+" "+day; 212 } 213 else 214 { 215 month=month-1; 216 day=31; 217 a=year+" "+month+" "+day; 218 } 219 220 } 221 222 223 else if(month==5||month==7||month==10||month==12) 224 { 225 if(day>1) 226 { 227 day=day-1; 228 a=year+" "+month+" "+day; 229 } 230 else 231 { 232 month=month-1; 233 day=30; 234 a=year+" "+month+" "+day; 235 } 236 237 } 238 else if(month==3) 239 { 240 if(isLeapYear(year)==true) 241 { 242 if(day>1) 243 { 244 day=day-1; 245 a=year+" "+month+" "+day; 246 } 247 else 248 { 249 month=month-1; 250 day=29; 251 a=year+" "+month+" "+day; 252 } 253 } 254 else 255 { 256 if(day>1) 257 { 258 day=day-1; 259 a=year+" "+month+" "+day; 260 } 261 else 262 { 263 month=month-1; 264 day=28; 265 a=year+" "+month+" "+day; 266 } 267 } 268 } 269 else { 270 if(day>1) 271 { 272 day=day-1; 273 a=year+" "+month+" "+day; 274 } 275 else 276 { 277 year = year-1; 278 month=12; 279 day=31; 280 a=year+" "+month+" "+day; 281 } 282 } 283 return a; 284 } 285 }
由于只有一个类,过于简单,因此此处不放置类图进行介绍。
针对于本题而言,与题目集2的7-4的题目其实大相径庭。只不过这一题主要是为了求一个日期的前后N天(N为正值取前N天,为负时去后N天)。两题的方法都差不多,但是本题需要注意不是一天,而是N天进行计算,所以会有跨月、跨年等情况,以及平年闰年大月小月等情况,对于边界值等,都需要去注意。本题主要考察细节问题,考察方法调用,在Main类中灵活调用方法实现功能。
题目集3的7-2代码如下;
1 import java.util.Scanner; 2 public class Main { 3 4 public static void main(String[] args) { 5 // TODO Auto-generated method stub 6 Scanner scanner = new Scanner(System.in); 7 int year = scanner.nextInt(); 8 int month = scanner.nextInt(); 9 int day = scanner.nextInt(); 10 if(Date.checkinputValidity(year,month,day)==true) 11 { 12 Date.getNextDate(year,month,day); 13 } 14 else 15 { 16 System.out.print("Date Format is Wrong"); 17 } 18 } 19 20 } 21 22 23 class Date { 24 private int year ; 25 private int month; 26 private int day; 27 public Date(){} 28 public int[] mon_maxnum = new int[] {0,31,28,31,30,31,30,31,31,30,31,30,31}; 29 public int getYear() { 30 return year; 31 } 32 public void setYear(int year) { 33 this.year = year; 34 } 35 public int getMonth() { 36 return month; 37 } 38 public void setMonth(int month) { 39 this.month = month; 40 } 41 public int getDay() { 42 return day; 43 } 44 public void setDay(int day) { 45 this.day = day; 46 } 47 public static boolean isLeapYear(int year) { 48 if(year%4==0&&year%100!=0||year%400==0) { 49 return true; 50 } 51 else { 52 return false; 53 } 54 } 55 public static boolean checkinputValidity(int year,int month,int day) { 56 if(year>=1900&&year<=2000&&month>0&&month<13&&day>0&&day<32) { 57 if(month==1||month==3|month==5||month==7||month==8||month==10||month==12) { 58 if(day>=1&&day<=31) { 59 return true; 60 } 61 else { 62 return false; 63 } 64 } 65 else if(month==4||month==6|month==9||month==11) { 66 if(day>=1&&day<=30) { 67 return true; 68 } 69 else { 70 return false; 71 } 72 } 73 else { 74 if(isLeapYear(year)==true) { 75 if(day>=1&&day<=29) { 76 return true; 77 } 78 else { 79 return false; 80 } 81 } 82 else { 83 if(day>=1&&day<=28) { 84 return true; 85 } 86 else { 87 return false; 88 } 89 } 90 91 } 92 } 93 else { 94 return false; 95 } 96 97 } 98 99 public static void getNextDate(int year, int month, int day) { 100 if(month==1||month==3|month==5||month==7||month==8||month==10||month==12) 101 { 102 if(day>=0&&day<=30) 103 { 104 day=day+1; 105 System.out.print("Next day is:" + year + "-" + month + "-" + day); 106 } 107 else if(day==31) 108 { 109 if(month==12) 110 { 111 year=year+1; 112 month=1; 113 day=1; 114 System.out.print("Next day is:" + year + "-" + month + "-" + day); 115 } 116 else 117 { 118 month=month+1; 119 day=1; 120 System.out.print("Next day is:" + year + "-" + month + "-" + day); 121 } 122 } 123 else 124 { 125 System.out.print("Date Format is Wrong"); 126 } 127 } 128 else if(month==4||month==6|month==9||month==11) 129 { 130 if(day>=0&&day<=29) 131 { 132 day=day+1; 133 System.out.print("Next day is:" + year + "-" + month + "-" + day); 134 } 135 else if(day==30) 136 { 137 month=month+1; 138 day=1; 139 System.out.print("Next day is:" + year + "-" + month + "-" + day); 140 } 141 else 142 { 143 System.out.print("Date Format is Wrong"); 144 } 145 } 146 else 147 { 148 if(isLeapYear(year)==true) 149 { 150 if(day>=0&&day<=28) 151 { 152 day=day+1; 153 System.out.print("Next day is:" + year + "-" + month + "-" + day); 154 } 155 else if(day==29) 156 { 157 month=month+1; 158 day=1; 159 System.out.print("Next day is:" + year + "-" + month + "-" + day); 160 } 161 else 162 { 163 System.out.print("Date Format is Wrong"); 164 } 165 } 166 else 167 { 168 if(day>=0&&day<=27) 169 { 170 day=day+1; 171 System.out.print("Next day is:" + year + "-" + month + "-" + day); 172 } 173 else if(day==28) 174 { 175 month=month+1; 176 day=1; 177 System.out.print("Next day is:" + year + "-" + month + "-" + day); 178 } 179 else 180 { 181 System.out.print("Date Format is Wrong"); 182 } 183 } 184 185 186 } 187 } 188 }

本题类图如上,主要分为两个类,Main类运行程序,通过Date类实现相关功能。本题主要考察同学们对于类的封装性的理解,以及类与对象,类的私有属性等知识。关于类的封装性我查阅资料后有如下看法:
封装讲类的某些信息隐藏在类内部,不允许外部程序直接访问,只能通过该类提供的方法来实现对隐藏信息的操作和访问。封装的特点:只能通过规定的方法访问数据;隐藏类的实例细节,方便修改和实现。实现封装的具体步骤如下:1.修改属性的可见性来限制对属性的访问,一般设为private;2.为每个属性创建一对赋值(setter)方法和取值(getter)方法,一般设为public,用于属性的读写;3.在赋值和取值方法中,加入属性控制语句(对属性值的合法性进行判断)。
题目集3的7-3代码如下:
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 import java.util.regex.Matcher; 4 import java.util.regex.Pattern; 5 6 public class Main { 7 public static void main(String[] args) { 8 Scanner input = new Scanner(System.in); 9 String a = input.nextLine(); 10 a=a.replaceAll(" ", ""); 11 12 String b =deal1(a);//将次方后面的负次幂进行变换 13 if(b.length()==0) { 14 System.out.println("Wrong Format"); 15 } 16 else if(b.equals("0")) { 17 System.out.println(b); 18 } 19 else { 20 deal2(b); 21 } 22 23 } 24 public static String deal1(String a) { 25 26 int n=a.indexOf("x"); 27 if(n==-1) { 28 a="0"; 29 } 30 else { 31 for(int i=0;n>-1;i++) { 32 if(n==0) { 33 a="1*"+a; 34 } 35 else if(a.charAt(n-1)=='-'||a.charAt(n-1)=='+') { 36 a=a.substring(0,n)+"1*"+a.substring(n+1); 37 } 38 else if(a.charAt(n-1)=='*') { 39 if(a.charAt(n-2)=='0'){ 40 if(a.charAt(n-3)=='+'||a.charAt(n-3)=='-') { 41 a=""; 42 } 43 44 } 45 } 46 else if(a.charAt(n+1)=='^') { 47 if(a.charAt(n+2)=='0'){ 48 a=""; 49 } 50 } 51 n=a.indexOf("x",n+1); 52 53 } 54 } 55 56 int []b = new int[10] ; 57 58 int f=a.indexOf("^"); 59 for(int i=0;f>-1;i++) { 60 61 b[i] = f; 62 63 if(a.charAt(f+1)=='-') { 64 a=a.substring(0,f+1)+"!"+a.substring(f+2); 65 } 66 f=a.indexOf("^",f+1); 67 68 } 69 70 71 return a; 72 73 } 74 public static void deal2(String a) { 75 int []b = new int[10] ; 76 int []c = new int[10] ; 77 String []str = new String[10]; 78 int f1=0; 79 int f2=0; 80 int f=0; 81 int n =0; 82 for(int i=0;f1!=100&&f2!=100;i++) { 83 f1=a.indexOf('+',f1); 84 f2=a.indexOf('-',f2); 85 if(f1==f2&&f1==-1) { 86 f=1; 87 } 88 if(f1==-1) { 89 f1=100; 90 } 91 if(f2==-1) { 92 f2=100; 93 } 94 95 if(f1<f2) { 96 b[i]=f1;f1++; 97 } 98 else { 99 b[i]=f2;f2++; 100 } 101 n++; 102 103 104 } 105 if(f==0) { 106 String s=""; 107 108 if(b[0]==0) { 109 for(int i=0;i<n;i++) { 110 111 112 if(b[i]==0&&i==0) { 113 str[i]=a.substring(b[i],b[i+1]); 114 115 } 116 else if(i==0) { 117 str[i]=a.substring(0,b[i]); 118 } 119 else if(i==n-1){ 120 str[i]=a.substring(b[i]); 121 } 122 else { 123 str[i]=a.substring(b[i],b[i+1]); 124 } 125 126 127 s=s+deal3(str[i]); 128 } 129 } 130 131 else { 132 for(int i=0;i<n;i++) { 133 134 135 136 if(i==0) { 137 str[i]=a.substring(0,b[i]); 138 } 139 140 else { 141 str[i]=a.substring(b[i-1],b[i]); 142 } 143 144 145 146 } 147 str[n]=a.substring(b[n-1]); 148 149 for(int i=0;i<n+1;i++) { 150 151 s=s+deal3(str[i]); 152 153 } 154 } 155 156 157 if(s.length()==0) { 158 System.out.print("0"); 159 160 } 161 else { 162 if(s.charAt(0)=='+') { 163 System.out.print(s.substring(1)); 164 } 165 else { 166 System.out.print(s); 167 } 168 } 169 } 170 else { 171 172 System.out.print(deal3(a)); 173 } 174 175 176 177 } 178 public static String deal3(String a) { 179 180 int n = a.indexOf('x'); 181 if(n<0) { 182 a=""; 183 } 184 else if(a.length()==n+1) { 185 a=a.substring(0,n-1); 186 } 187 else { 188 if(a.charAt(0)=='-') { 189 if(a.charAt(n+2)=='!') { 190 int s = Integer.parseInt(a.substring(n+3))+1; 191 int s2 = Integer.parseInt(a.substring(n+3))*Integer.parseInt(a.substring(1,n-1)); 192 a = "+"+s2+"*x^-"+s; 193 } 194 else { 195 int s = Integer.parseInt(a.substring(n+2))-1; 196 int s2 = Integer.parseInt(a.substring(n+2))*Integer.parseInt(a.substring(1,n-1)); 197 a = "-"+s2+"*x^"+s; 198 } 199 } 200 else if(a.charAt(0)=='+') { 201 if(a.charAt(n+2)=='!') { 202 int s = Integer.parseInt(a.substring(n+3))+1; 203 String a1 = a.substring(1,n-1); 204 BigInteger a2= new BigInteger(a1); 205 String a3 = a.substring(n+3); 206 BigInteger a4= new BigInteger(a3); 207 BigInteger s2 = a2.multiply(a4); 208 a = "-"+s2+"*x^-"+s; 209 } 210 else { 211 int s = Integer.parseInt(a.substring(n+2))-1; 212 int s2 = Integer.parseInt(a.substring(n+2))*Integer.parseInt(a.substring(1,n-1)); 213 a = "+"+s2+"*x^"+s; 214 } 215 } 216 else { 217 if(a.charAt(n+2)=='!') { 218 219 int s = Integer.parseInt(a.substring(n+3))+1; 220 int s2 = Integer.parseInt(a.substring(n+3))*Integer.parseInt(a.substring(0,n-1)); 221 a = "-"+s2+"*x^-"+s; 222 } 223 else { 224 int s = Integer.parseInt(a.substring(n+2))-1; 225 int s2 = Integer.parseInt(a.substring(n+2))*Integer.parseInt(a.substring(1,n-1)); 226 a = "+"+s2+"*x^"+s; 227 } 228 } 229 } 230 return a; 231 232 } 233 234 } 235 //if(s!=1) { 236 // a = "-"+s2+"*x^"+s; 237 //} 238 //else { 239 // a = "-"+s2+"*x"; 240 //} 241 //-2*x^-2+5*x^12-4*x+12-2*x^-2
本题难度过大,并没有写出完整代码,代码仅供参考。
对于本题而言,主要考察学生对于正则表达式的自主学习,对于BigInteger的自主学习,对于replaceAll的使用,以及分割字符。本题感觉难度很大,我目前无法做出来,还需要后续多加学习。
3.采坑心得
1.编译错误:pta提交作业机制严格,需要主类必须为Main,否则无法通过;
2.格式错误:多个类进行提交,其它类不需要public;
3.答案错误:答案输出有问题,答案格式与pta给的格式不符;
4.改进意见
编码是注意规范编码,感觉自己的编码风格有点乱,之后的编码过程中,需要注意自己的编码,要做的规范编码。对于类的封装性还是需要多加强学习,对于正则表达式也需要后续的学习,在之后把一元多项式求导写出来。
5.总结
三次题目集,让我对于java有了一个基础的认识,学会了java的输入输出,了解了Scanner包,BigInteger包等,对于方法的调用、类与对象的使用、属性的私有性、类的封装性都有了一个简单的理解,并且通过自学了解了一点正则表达式的知识,虽然对于正则表达式了解的还是很少,但是在之后的学习过程中,我还是需要好好学习正则表达式,以及对于ArrayList数组也需要进行一个学习。
建议:对于基础不好的我,PTA题目集的难度有些偏大,每次完成全部题目都得花大量时间,希望老师能够多次作业并逐步增加难度,这样的话有助于基础偏弱的人学的更好。对于PTA的题量的话,在慢慢增加难度的前提下,也可以适当增加一两题,以便更好地巩固知识。

浙公网安备 33010602011771号