救教下面一个小问题,小弟是新学者。请教前辈们
import java.util.*;public class TestVector {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
int sum=0;
TestVector v=new TestVector();
System.out.println("please enter number");
while ( true )
{
int b=System.in.read();
if (b=='\r'||b=='\n')
break;
else
{
int num=b-'0';
v.add(new Integer(num) ) ;
}
}
// TODO: Add your code here
}
Enumeration e = v.element();
while(e.hasMoreElements())
{
Integer ww = (Integer) e.nextElement();
sum+=ww.valueOf();
}
System.out.println( sum );
}
import java.util.*;
public class TestVector {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
int sum=0;
TestVector v=new TestVector();
System.out.println("please enter number");
while ( true )
{
int b=System.in.read();
if (b=='\r'||b=='\n')
break;
else
{
int num=b-'0';
v.add(new Integer(num) ) ;
}
}
// TODO: Add your code here
}
Enumeration e = v.element();
while(e.hasMoreElements())
{
Integer ww = (Integer) e.nextElement();
sum+=ww.valueOf();
}
System.out.println( sum );
}
调试时
while(e.hasMoreElements()) 提示本行:非法类型的开始
System.out.println( sum ); 提示:需要《标识符》
时怎么回事呢?
请教前辈们
谢谢