Как я понимаю, всё из-за того, что при вводе цифры, к ней добавляется "Ура" и тогда она не добавляется к сумме.
package com.javarush.task.task16.task1632;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.ScatteringByteChannel;
import java.util.ArrayList;
import java.util.List;
/*
Клубок
*/
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static {
threads.add(new Infinity());
threads.add(new InterruptedExceptionPrinter());
threads.add(new PrintUra());
threads.add(new MessageInterface());
threads.add(new Numbers());
}
public static void main(String[] args) {
for (Thread thread : threads) {
thread.start();
}
}
}
class Infinity extends Thread {
@Override
public void run() {
while (true) {
}
}
}
class InterruptedExceptionPrinter extends Thread {
@Override
public void run() {
try {
Thread.sleep(100000);
} catch (InterruptedException interruptedException) {
System.out.println("InterruptedException");
}
}
}
class PrintUra extends Thread {
@Override
public void run() {
while (true) {
try {
System.out.println("Ура");
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class MessageInterface extends Thread implements Message {
boolean isAlive = true;
@Override
public void run() {
while (isAlive) {
}
}
@Override
public void showWarning() {
isAlive = false;
}
}
class Numbers extends Thread {
@Override
public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int result = 0;
while (true) {
try {
String string = reader.readLine();
if (!string.equals("N") && string.matches("\\d+")) {
result += Integer.parseInt(string);
} else if (string.equals("N")) {
System.out.println(result);
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}