import java.util.*;
public class TestCollection {
public static void main(String[] args) {
int b=0;
ArrayList a=new ArrayList();
System.out.println("请输入数字:");
while(true){
try {
b=System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
if(b=='\r'||b=='\n'){
return;
}else{
int c=b-'0';
a.add(new Integer(c));
}
}
int sum=0; //这一行总报错
Iterator i=a.iterator(); //若把这一行和上面一行调换位置又变成这一句代码报错
while(i.hasNext()){
Integer objInt=(Integer)i.next();
sum +=objInt;
System.out.println(sum);
}
}
}
public class TestCollection {
public static void main(String[] args) {
int b=0;
ArrayList a=new ArrayList();
System.out.println("请输入数字:");
while(true){
try {
b=System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
if(b=='\r'||b=='\n'){
return;
}else{
int c=b-'0';
a.add(new Integer(c));
}
}
int sum=0; //这一行总报错
Iterator i=a.iterator(); //若把这一行和上面一行调换位置又变成这一句代码报错
while(i.hasNext()){
Integer objInt=(Integer)i.next();
sum +=objInt;
System.out.println(sum);
}
}
}
解决方案 »
- jsp中添加日历控件
- 如何在MAC下创建简单的下拉框(非默认的)
- Hibernate的保存问题
- servlet + javabean 如何做高效的数据库连接?
- 我想把java程序做成windows服务
- 高手帮忙!tomcat问题,有效立即给分结贴!在线等
- InternetAddress.parse("*@*.com",false),false指什么意思?
- 我的J2EE_HOME怎么设置不对?
- 控制台正确输出sql,但是数据库没有数据
- 问下,现在微信朋友圈还能自动跳转到浏览器么?
- 关于javax.persistence.OneToMany.orphanRemoval()Z 的问题
- SSH基础问题求教!
while(true){
try {
b=System.in.read();
} catch (Exception e) {e.printStackTrace();
}
if(b=='\r'||b=='\n'){
return;//些处改为break;否则while循环以下的代码是永远不会执行的
}else{
int c=b-'0';
a.add(new Integer(c));
}
}