同一段代码为何终端运行和eclipse运行结果不一样?

博主遇到一个奇怪的问题,同一段Java代码在Eclipse IDE中运行无法跳出while循环,导致无法输出"jump!",但通过终端编译运行则能正常工作。问题在于IDE的Run Configuration设置可能与终端命令行存在差异,目前原因未知。
摘要由CSDN通过智能技术生成

先挖个坑,日后来填!

跟着java核心技术365页的示例程序实现了一遍,发现在IDE环境下,跑不出结果,而在终端中运行就能出结果,代码如下:

package set;

import java.util.*;

public class SetTest {
	public static void main(String[] args)
	{
		Set<String> words=new HashSet<String>();
		long totalTime=0;
		
		try(Scanner in=new Scanner(System.in))
		{
			while(in.hasNext())
			{
				String word=in.next();
				System.out.println(word);
				long callTime=System.currentTimeMillis();
				words.add(word);
				callTime=System.currentTimeMillis()-callTime;
				totalTime+=callTime;
				System.out.println("OK!");   //程序会一直卡在while里出不来
			}
			System.out.println("jump!");
		}
		
		
		Iterator<String> a=words.iterator();
		int i=0;
		while(a.hasNext()&&i<=20) 
		{
			System.out.println(a.next());
			i++;
		}
		System.out.println(words.size()+"distinct words."+totalTime+"mil
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值