Hashtable这么写为什么不能运行

城续缘 2017-11-05 09:44:32
//import java.lang.*;
import java.util.Hashtable;
import java.util.Enumeration;
public class HashApp {
public static void main(String args[])
{ Hashtable hash=new Hashtable(2,(float)0.8);
hash.put("jiangsu","Nanjing");
hash.put("Bejing","Bejing");
hash.put("zhejiang", "Hanfzhou");
System.out.println("The hashtable hash1 is:"+hash);
System.out.println("The size of this hash table is"+hash.size());
Enumeration enuml=hash.elements();
System.out.println("The element of hash is:");
while (enuml.hasMoreElements())
{
System.out.println( enuml.nextElement()+" ");
System.out.println( );
}
if (hash.containsKey("Jiangsu"))
{
System.out.println( "The capatial of Jiangsu is "+hash.get("Jiangsu"));
hash.remove("Bejing");
System.out.println("The hashtable hash2 is:"+hash);
System.out.println("The size of this hash table is"+hash.size());

}

}
...全文
226 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
城续缘 2017-11-10
  • 打赏
  • 举报
回复
是少了个 }
城续缘 2017-11-10
  • 打赏
  • 举报
回复
哎呀,没看到
自由自在_Yu 2017-11-06
  • 打赏
  • 举报
回复
import java.util.Enumeration;
import java.util.Hashtable;

/**
 * Description:
 * 
 * @author 
 * @Date 2017年10月18日
 */
public class HashApp {

	public static void main(String args[]) {
		Hashtable<String,String> hash = new Hashtable<String,String>(2, (float) 0.8);
		hash.put("jiangsu", "Nanjing");
		hash.put("Bejing", "Bejing");
		hash.put("zhejiang", "Hanfzhou");
		System.out.println("The hashtable hash1 is:" + hash);
		
		System.out.println("The size of this hash table is" + hash.size());
		
		Enumeration<String> enuml = hash.elements();
		System.out.println("The element of hash is:");
		while (enuml.hasMoreElements()) {
			System.out.println(enuml.nextElement() + " ");
			System.out.println();
		}
		
		if (hash.containsKey("Jiangsu")) {
			System.out.println("The capatial of Jiangsu is "
					+ hash.get("Jiangsu"));
			hash.remove("Bejing");
			System.out.println("The hashtable hash2 is:" + hash);
			System.out.println("The size of this hash table is" + hash.size());

		}
	}
}
可以运行的,结果是 The hashtable hash1 is:{jiangsu=Nanjing, zhejiang=Hanfzhou, Bejing=Bejing} The size of this hash table is3 The element of hash is: Nanjing Hanfzhou Bejing 看看你的代码是不是少了“{“,”}”
自由自在_Yu 2017-11-06
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
可以运行啊。。。
好像少了一个“}”
李德胜1995 2017-11-05
  • 打赏
  • 举报
回复
可以运行啊。。。

58,454

社区成员

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

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