荣耀第一题,通过率只有60%,这是为什么?错在哪了?求解
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String srr = sc.nextLine();
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = srr.substring(i*9,i*9+9);
}
System.out.println(Arrays.toString(arr));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
String s = arr[i];
if(s.charAt(0) == '0'){
sb.append(s.substring(1,9));
arr[i] = sb.reverse().toString();
}else{
arr[i] = s.substring(1,9);
}
}
for (int i = 0; i < n; i++) {
System.out.printf(arr[i]+" ");
}
}
}
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String srr = sc.nextLine();
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = srr.substring(i*9,i*9+9);
}
System.out.println(Arrays.toString(arr));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
String s = arr[i];
if(s.charAt(0) == '0'){
sb.append(s.substring(1,9));
arr[i] = sb.reverse().toString();
}else{
arr[i] = s.substring(1,9);
}
}
for (int i = 0; i < n; i++) {
System.out.printf(arr[i]+" ");
}
}
}
全部评论
你这谁愿意看啊 最少代码整齐点啊
sb没有重新new过?
StringBuilder 的问题吧 其实完全可以在if else语句中直接 输出的,这种笔试就不要为难自己了
相关推荐