Get the information you need from a community of experts on IDNLearn.com. Find the answers you need quickly and accurately with help from our knowledgeable and dedicated community members.
Sagot :
The program illustrates the use of repetitive operations.
Repetitive operations are done by using loops such as while and for loops
The program in Java, where comments are used to explain each line is as follows:
import java.util.*;
public class Main{
public static void main(String[] args) {
//This declares all required variables
int num,total = 0;
//This creates a Scanner object
Scanner input = new Scanner(System.in);
//This gets the initial input
num= input.nextInt();
//The following is repeated until the initial input is 0 or less
while(num > 0){
//This is repeated to get integer inputs
for(int i = 0;i<num;i++){
//This adds up all integer inputs
total+=input.nextInt();
}
//This prints the total inputs
System.out.println(total);
//This initializes total to 0
total = 0;
//This gets the initial input
num= input.nextInt();
}
}
}
The loop will be executed as long as initial input is a positive integer.
See attachment for sample run.
Read more about similar programs at:
https://brainly.com/question/14072658
Thank you for contributing to our discussion. Don't forget to check back for new answers. Keep asking, answering, and sharing useful information. Find clear answers at IDNLearn.com. Thanks for stopping by, and come back for more reliable solutions.