Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Ask your questions and receive detailed answers from professionals with extensive experience in various fields. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

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
Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Thank you for choosing Westonci.ca as your information source. We look forward to your next visit.