| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 553 人关注过本帖
标题:java.lang.outmemoryerror
只看楼主 加入收藏
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
 问题点数:0 回复次数:3 
java.lang.outmemoryerror

请问这是什么错误? 我编译已经通过了。。。

import java.util.Stack;
import java.io.*;
public class addlongnum{

public Stack ran(){ 输入一些数存到堆栈中,并且返回这个堆栈
Stack a= new Stack();
try{

char num=(char)System.in.read();
while (num!='\n'){

a.push(new Character(num)) ;}
} catch (Exception e){}
return a;
}

public void statues(Stack a){ 把堆栈中的元素都打印出来
while (a.isEmpty()==false){
System.out.print(a.pop()+" ");
}
}


public Stack addlongnum(Stack a,Stack b){//长整数加法 就是把a,b两个堆栈中的数逐一取出相加然后存在另一个堆栈中
Object tem=new Object();
Object tema=new Object();
Object temb=new Object();
int d=0;
Stack stack=new Stack();
for(;a.isEmpty()==false&&b.isEmpty()==false;){
tema=a.pop();temb=b.pop();
int c = Integer.parseInt(tema.toString())+Integer.parseInt(temb.toString())+d;
if(c<=9)
d=0;
else
{
d=1;
c=c-10;
}
stack.push(new Integer(c));
}
for(;a.isEmpty()==false;){
if(d==1){
tema=a.pop();
int e=Integer.parseInt(tema.toString())+d;
stack.push(new Integer(e));
d=0;
}
else
{
stack.push(a.pop());
}
}
for(;b.isEmpty()==false;){
if(d==1){
temb=b.pop();
int e=Integer.parseInt(temb.toString())+d;
stack.push(new Integer(e));
d=0;
}
else
{
stack.push(b.pop());
}

}

return stack;
}

public static void main(String arg[]) {
Stack a=new Stack();
Stack b=new Stack();

addlongnum xiaohe =new addlongnum();
System.out.println("enter a");
a=xiaohe.ran(); 显示到这就弹出错误!!!
System.out.println("enter b");
b=xiaohe.ran();
xiaohe.statues(xiaohe.addlongnum(a,b));
}
}

[此贴子已经被作者于2007-1-11 1:53:50编辑过]

搜索更多相关主题的帖子: public return import color 
2007-01-11 01:46
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
得分:0 
不好意思,发现 public Stack ran(){ 输入一些数存到堆栈中,并且返回这个堆栈
Stack a= new Stack();
try{

char num=(char)System.in.read();
while (num!='\n'){

a.push(new Character(num)) ;
num=(char)System.in.read(); } 这儿少了一句
} catch (Exception e){}
return a;
} 不过运行后还是错误,不能将两个数相加。。。
2007-01-11 02:27
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你递归调用了吧,要么怎么会出现内存溢出的异常呢
你的代码我没有看,你再检查一遍吧

可惜不是你,陪我到最后
2007-01-11 09:37
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
得分:0 
解决方法。。。。
try{
c = Integer.parseInt(tema.toString())+Integer.parseInt(temb.toString())+d;

}catch(NumberFormatException nfe){}
2007-01-11 20:16
快速回复:java.lang.outmemoryerror
数据加载中...
 
   



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

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