feeb.reverse().toString()
时间: 2023-06-23 16:02:14 浏览: 40
这段代码的作用是将StringBuffer对象feeb中的字符序列进行倒序操作,并返回倒序后的字符串形式。StringBuffer类中的reverse()方法可以将字符序列反转,返回值类型为StringBuffer。而调用toString()方法则可以将StringBuffer对象转换成字符串形式。因此,feeb.reverse().toString()的返回值是倒序后的字符串。
相关问题
for (int i = 0; i < len / 3; i++) { temp += fee.subSequence(i * 3, 3 + 3 * i) + ","; } feeb = new StringBuffer(temp); student[4] = head + feeb.reverse().toString() + ".00"; System.out.println("添加成功,您输入的学生信息如下: "); System.out .print("First Name\t Last Name\t\t ID\t\t\tMajor\t\t\tFee\n"); toString(student); new studentList().addNewStudent(student, file); System.out.printf("\n"); return true; }
这段代码的作用是将分割后的字符串组合成最终的带有美元符号和两位小数的字符串,并将其添加到学生信息数组的第五个位置。首先,使用for循环遍历分割后的字符串,每三个字符加一个逗号,并将结果添加到temp字符串中。接着,将temp字符串转换成StringBuffer对象feeb,并对其进行倒序操作。最后,将头部字符串head、倒序后的feeb字符串和美元符号以及两位小数组合成完整的费用字符串,并将其添加到学生信息数组的第五个位置。接下来,输出添加成功和学生信息表头。然后,调用toString方法输出学生信息,并将学生信息添加到学生列表中。最后,输出一个换行符并返回添加学生信息成功的布尔值true。
String temp = ""; String head = null; int len = fee.length(); if (len % 3 == 0) { len--; head = fee.subSequence(0, 3) + ""; } else { head = fee.subSequence(0, len % 3) + ""; } StringBuffer feeb = new StringBuffer(fee);
这段代码的作用是将费用转换为带有逗号的形式。首先定义一个空字符串temp和一个头部字符串head,然后获取费用字符串的长度len。如果len能被3整除,那么将len减1并将费用字符串中的前三个字符赋值给head。否则,将费用字符串中的前len%3个字符赋值给head。接着,将费用字符串fee转换成StringBuffer对象feeb。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)