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.

JAVA A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is 0 or negative. Ex: If the user enters 3 9 6 1 0, the output is:

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

View image MrRoyal