热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

学习java总结

OO前三次作业总结1.前言题目集1的知识点:Scanner的输入,以及java的简单输出;java的if-else选择分支结构;java的for循环结构;简单的数组排序。题目集1的题量:1.计算两个数

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 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 }

学习java总结 - 文章图片

&#160;

&#160;

&#160;本题类图如上,主要分为两个类,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)==&#39;-&#39;||a.charAt(n-1)==&#39;+&#39;) {
36 a=a.substring(0,n)+"1*"+a.substring(n+1);
37 }
38 else if(a.charAt(n-1)==&#39;*&#39;) {
39 if(a.charAt(n-2)==&#39;0&#39;){
40 if(a.charAt(n-3)==&#39;+&#39;||a.charAt(n-3)==&#39;-&#39;) {
41 a="";
42 }
43
44 }
45 }
46 else if(a.charAt(n+1)==&#39;^&#39;) {
47 if(a.charAt(n+2)==&#39;0&#39;){
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)==&#39;-&#39;) {
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(&#39;+&#39;,f1);
84 f2=a.indexOf(&#39;-&#39;,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 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;i110
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;i133
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;i150
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)==&#39;+&#39;) {
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(&#39;x&#39;);
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)==&#39;-&#39;) {
189 if(a.charAt(n+2)==&#39;!&#39;) {
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)==&#39;+&#39;) {
201 if(a.charAt(n+2)==&#39;!&#39;) {
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)==&#39;!&#39;) {
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的题量的话,在慢慢增加难度的前提下,也可以适当增加一两题,以便更好地巩固知识。


推荐阅读
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Java中包装类的设计原因以及操作方法
    本文主要介绍了Java中设计包装类的原因以及操作方法。在Java中,除了对象类型,还有八大基本类型,为了将基本类型转换成对象,Java引入了包装类。文章通过介绍包装类的定义和实现,解答了为什么需要包装类的问题,并提供了简单易用的操作方法。通过本文的学习,读者可以更好地理解和应用Java中的包装类。 ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • 本文详细介绍了Python中正则表达式和re模块的使用方法。首先解释了转义符的作用,以及如何在字符串中包含特殊字符。然后介绍了re模块的功能和常用方法。通过学习本文,读者可以掌握正则表达式的基本概念和使用技巧,进一步提高Python编程能力。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 不同优化算法的比较分析及实验验证
    本文介绍了神经网络优化中常用的优化方法,包括学习率调整和梯度估计修正,并通过实验验证了不同优化算法的效果。实验结果表明,Adam算法在综合考虑学习率调整和梯度估计修正方面表现较好。该研究对于优化神经网络的训练过程具有指导意义。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • OO第一单元自白:简单多项式导函数的设计与bug分析
    本文介绍了作者在学习OO的第一次作业中所遇到的问题及其解决方案。作者通过建立Multinomial和Monomial两个类来实现多项式和单项式,并通过append方法将单项式组合为多项式,并在此过程中合并同类项。作者还介绍了单项式和多项式的求导方法,并解释了如何利用正则表达式提取各个单项式并进行求导。同时,作者还对自己在输入合法性判断上的不足进行了bug分析,指出了自己在处理指数情况时出现的问题,并总结了被hack的原因。 ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
author-avatar
常年等奖中869
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有