Implement a sum subscriber

Report a typo

Implement the SumSubscriber class that calculates the sum of numbers from a data stream.

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();
___

Create a free account to access the full topic