Ask Question
11 May, 22:31

Write a for loop that runs 5 times and accepts the input of an integer number every time. Those numbers will be accumulated by a variable called total.

+1
Answers (1)
  1. 12 May, 01:52
    0
    import java. util. Scanner;

    public class num2 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    int total = 0;

    for (int i=0; i<5; i++) {

    System. out. println ("Enter next Int: ");

    total = total+in. nextInt ();

    }

    System. out. println (total);

    }

    }

    Explanation:

    In the code above written in Java programming language, the for loop statement for (int i=0; i<5; i++) ensures that the loop goes from 0-4 a total of five times.

    At each iteration it requests a user to enter an int. The number entered is stored in the variable total which is initially assigned 0.

    When the loop finishes execution, total is printed out
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a for loop that runs 5 times and accepts the input of an integer number every time. Those numbers will be accumulated by a variable ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers