标题:要用什么来储存一个非常非常大的字符串?用String来储存不够大啊~~请你们路 ...
取消只看楼主
llt2013
Rank: 2
等 级:论坛游民
帖 子:15
专家分:20
注 册:2013-12-28
结帖率:50%
已结贴  问题点数:20 回复次数:1 
要用什么来储存一个非常非常大的字符串?用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)
搜索更多相关主题的帖子: public 字符串 
2014-12-13 16:38
llt2013
Rank: 2
等 级:论坛游民
帖 子:15
专家分:20
注 册:2013-12-28
得分:0 
回复 2楼 编号1016
因为我A【0】已经给定了,所以我只要再输入25位就好了,然后A。length=26,从i=1开始就刚好25位啦
2014-12-14 01:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439901-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120874 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved