要用什么来储存一个非常非常大的字符串?用String来储存不够大啊~~请你们路过就来瞄瞄我吧~~感恩~
public class T9 {public static void main(String [] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt()-1;
String [] a={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String [] A=new String[26];
A[0]=a[0];
for (int i = 1; i <A.length; i++) {//就是这里出了问题导致运行不了如果将A。length改小一点就可以运行
A[i]=A[i-1]+a[i]+A[i-1];
}
System.out.println(A[n]);
}
}
运行之后显示
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2367)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
at java.lang.StringBuilder.append(StringBuilder.java:132)
at T9.main(T9.java:119)