Tag: 无限循环

使用BufferedReader读取所有行

我想使用BufferedReader在控制台中键入多行文本,当我点击“Enter”以查找整个文本长度的总和时。 问题是,我似乎进入了无限循环,当我按下“Enter”时,程序没有结束。 我的代码如下: InputStreamReader instream = new InputStreamReader(System.in); BufferedReader buffer = new BufferedReader(instream); line= buffer.readLine(); while (line!=null){ length = length + line.length(); line= buffer.readLine(); } 你能告诉我我做错了什么吗?

如何声明i和j使其成为无限循环?

while( i = j && i != j) {} 如何声明i和j使其成为无限循环? //这是我遇到的面试问题。 它问的是i和j的声明是什么,让它永远是真的。 我不能通过将i和j声明为数字类型来实现。 还有哪些类型可以满足它?

使用Scanner读取输入会导致Java中的无限循环

在我的程序中,我试图让用户在1-3之间输入一个int,然后根据他们键入的内容做一些事情。 如果它不是数字或不是其中一个选项,那么它将允许它们重新输入有效选项。 我遇到的问题是我无法集思广益,如何不让它无限循环,只是让它们在控制台告诉他们输入无效输入后输入一个数字。 int i = 0; while (i < 1) { try { int level = scan.nextInt(); i+=1; if (level == 1) { System.out.println("You selected level 1!"); //Start the game } else if (level == 2) { System.out.println("You selected level 2!"); //Start the game } else if (level == 3) { System.out.println("You selected level […]

在“while循环”中使用“try and catch”块时无限循环

当我在while循环中使用try和catch块时,我的程序有一个无限循环 。 import java.util.*; class Try { public static void main(String args[]) { Scanner sc=new Scanner(System.in); while(true) { try { System.out.println(“Enter a no “); int s=sc.nextInt(); } catch(Exception e) { System.out.println(“Invalid input try again”); } } } } 当我输入一个整数时,它运行正常并要求另一个输入,但是当我输入一个char时,它会进行无限循环。 为什么会这样?

无限循环当在try-catch块中捕获InputMidmatchException时

我一直在无限循环中捕获我的代码。 没什么可提升的,但我无法弄明白我的生活! 有人请帮忙 我只是重新创建了特定的错误,没有我在实际程序中的所有if语句。 package bs; import java.util.InputMismatchException; import java.util.Scanner; public class bs { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean continueVar = true; while (continueVar) { try { System.out.println(“Enter Something”); int input = sc.nextInt(); } catch (InputMismatchException i) { System.out.println(“What the f***?”); continueVar = true; } } } } […]

Kafka 0.8.2.2 – 无法发布消息

我们编写了一个用于向kafka发布消息的java客户端。 代码如下所示 Properties props = new Properties(); props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, “202.xx.xx.xxx:9092”); props.setProperty(ProducerConfig.METADATA_FETCH_TIMEOUT_CONFIG,Integer.toString(5 * 1000)); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName()); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName()); //1. create KafkaProducer KafkaProducer producer = new KafkaProducer(props); //2 create callback Callback callback = new Callback() { public void onCompletion(RecordMetadata metadata, Exception e) { System.out.println(“Error while sending data”); if (e != null); e.printStackTrace(); } }; producer.send(record, callback); 当我们执行此代码时,我们会收到以下消息和exception ProducerConfig values: compression.type […]

java.util.HashMap中的无限循环

我在这里经常有一些Vaadin代码阻塞,我不知道问题是什么: Thread 7892: (state = IN_JAVA) – java.util.HashMap.getEntry(java.lang.Object) @bci=61, line=349 (Compiled frame; information may be imprecise) – java.util.HashMap.containsKey(java.lang.Object) @bci=2, line=335 (Compiled frame) – java.util.HashSet.contains(java.lang.Object) @bci=5, line=184 (Compiled frame) – com.vaadin.ui.Table.unregisterPropertiesAndComponents(java.util.HashSet, java.util.HashSet) @bci=85, line=1693 (Compiled frame) – com.vaadin.ui.Table.refreshRenderedCells() @bci=992, line=1641 (Compiled frame) – com.vaadin.ui.Table.valueChange(com.vaadin.data.Property$ValueChangeEvent) @bci=23, line=2897 (Compiled frame) – com.vaadin.data.util.IndexedContainer.firePropertyValueChange(com.vaadin.data.util.IndexedContainer$IndexedContainerProperty) @bci=140, line=553 (Compiled frame) – com.vaadin.data.util.IndexedContainer.access$1000(com.vaadin.data.util.IndexedContainer, […]