大虾们,help me!这个错误搞了我一下午.

opou 2006-03-29 05:07:07
import java.util.*;
public class TestVector {

public static void main(String[] args) {
int b = 0;

Vector v = new Vector();
System.out.println("please enter number:");
int sum = 0;
while(true)
{
try
{
b = System.in.read();
}
catch(Exception e)
{
e.printStackTrace();
}
if (b == '\r'||b == '\n')
break;
else
{
int num = b - '0';
v.addElement(new Integer(num));
}

}
//int sum = 0;
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum += intObj.intValue();
}
}
System.out.println(sum);
}
错误是:
--------------------Configuration: TestVector - JDK version 1.5.0 <Default> - <Default>--------------------
F:\javawork\lesson2\TestVector.java:37: <identifier> expected
System.out.println(sum);
^
1 error

Process completed.
...全文
158 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
china2685920 2006-03-30
  • 打赏
  • 举报
回复
晕倒
hsuyuan 2006-03-30
  • 打赏
  • 举报
回复
System.out.println(sum);
要放到 main()方法的里面!!
捏造的信仰 2006-03-30
  • 打赏
  • 举报
回复
我无话可说,楼主1个月后再来看看你这篇帖子,就能体会到有多么搞笑了。
hero222 2006-03-30
  • 打赏
  • 举报
回复
emailfly(匆匆过客) ( ) 信誉:98 2006-03-29 17:17:00 得分: 0



System.out.println(sum);
要放到 main()方法的里面!!


同意!必须注意!变量的有效范围!

jeffaple 2006-03-29
  • 打赏
  • 举报
回复
一下午的了?
emailfly 2006-03-29
  • 打赏
  • 举报
回复

System.out.println(sum);
要放到 main()方法的里面!!
wenger 2006-03-29
  • 打赏
  • 举报
回复
import java.util.*;
public class TestVector {

public static void main(String[] args) {
int b = 0;

Vector v = new Vector();
System.out.println("please enter number:");
int sum = 0;
while(true)
{
try
{
b = System.in.read();
}
catch(Exception e)
{
e.printStackTrace();
}
if (b == '\r'||b == '\n')
break;
else
{
int num = b - '0';
v.addElement(new Integer(num));
}

}
//int sum = 0;
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum += intObj.intValue();
}
System.out.println(sum); //put it here
}

}
boyu_song 2006-03-29
  • 打赏
  • 举报
回复
System.out.println(sum);
写错地方了
idilent 2006-03-29
  • 打赏
  • 举报
回复
方到main里面好吗?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧