import java.util.*;
public class TestVector {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
Vector v = new Vector();
int b = 0;
// Enumeration e = new Enumeration();
System.out.println("please enter number:");
while(true)
{
try
{
b = System.in.read();
}
catch(Exception e)
{
}
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);
}
}
程序通过编译,但是提示使用了未经检查或不安全的操作。
要了解详细信息,请使用 -Xlint:unchecked 重新编译。
是什么原因导致的提示?
另外怎么编写能使此程序重复运行。直到用户输入bye的时候退出程序?
public class TestVector {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
Vector v = new Vector();
int b = 0;
// Enumeration e = new Enumeration();
System.out.println("please enter number:");
while(true)
{
try
{
b = System.in.read();
}
catch(Exception e)
{
}
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);
}
}
程序通过编译,但是提示使用了未经检查或不安全的操作。
要了解详细信息,请使用 -Xlint:unchecked 重新编译。
是什么原因导致的提示?
另外怎么编写能使此程序重复运行。直到用户输入bye的时候退出程序?
解决方案 »
- MyEclipse 包名目录结构怎么成这个样子了?。
- Socket问题 Connection reset?
- 使用JDBC桥连接MySQL数据库,把 ”JDBC驱动的类包解压到JAVA应用程序的运行目录“怎么理解这句话,”JAVA应用程序的运行目录“什么意思,具体问题请看:
- 求java程序写圆周率的算法
- 软件
- transient native volatile 这三个关键含义是什么呢?
- 关于树的代码问题
- 请问怎么在一个纯日文的2000环境下装一个英文的jdk?
- 在jTable的单元格中如何加入下拉框(JComboBox)?
- 数据转换,很土的问题
- 出现一个莫名其妙的异常,哪位好心人帮忙看看程序,感激不尽!!
- 怎么样让一个文本框获得焦点?
声明collection的时候指明存储的类型就没有警告了
楼主可以改成 Vector<Integer> v = new Vector<Integer>();
java.sun.com 上面有很多文档和 Tuturial .