Implement the SumSubscriber class that calculates the sum of numbers from a data stream.
Reactive programming concepts
Implement a sum subscriber
Report a typo
Write a program in Java 17
import java.util.Scanner;
import java.util.concurrent.Flow;
class SumSubscriber implements Flow.Subscriber<Integer> {
// Add fields if required
@Override
public void onNext(Integer integer) {
// implement me
}
public Long getSum() {
// implement me
}
// Do not change methods below
@Override
public void onSubscribe(Flow.Subscription s) {
// Empty
}
@Override
public void onError(Throwable t) {
// Empty
}
@Override
public void onComplete() {
// Empty
}
}
// Do not change the class
class Main {
public static void main(String[] args) {
SumSubscriber subscriber = new SumSubscriber();
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.