Question: Use scnr . nextInt ( ) to read integers from input into inputNumber until - 9 9 is read. For each remaining integer read before

Use scnr.nextInt() to read integers from input into inputNumber until -99 is read. For each remaining integer read before -99, if the integer is non-zero, output the integer followed by a newline and add the integer to sumOfSelected.
Ex: If the input is 0-21132421-99, then the output is:
-21
13
24
21
The sum of all non-zero values is 37 import java.util.Scanner;
public class SumOfSelected {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int inputNumber;
int sumOfSelected;
sumOfSelected =0;
/* Your code goes here */
System.out.println("The sum of all non-zero values is "+ sumOfSelected);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!