Respuesta :
The answer is total = 0;while(input.hasNextInt()){total += input.nextInt( );} Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of integers and an int variable named total, The code necessary to add all the integers in the input source and place their sum into total is : total = 0;while(input.hasNextInt()){total += input.nextInt( );}
Answer:
Following are the code written in the Java Programming Language.
total = 0; //set integer type variable and initialize to 0
while(input.hasNextInt()){ //set the while loop
total += input.nextInt( ); //code is here
}
Explanation:
Here, in the following code create the reference scanner class object i.e., "input".
- Then, we set integer data type variable "total" and initialize 0 in it.
- then, we set the while loop and pass the following condition "input.hasNextInt()".
- Then, we add all integer values and store their sum in the variable "total".