Ask Question
10 August, 10:17

Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program must use scanner for input of the 5 digits. Two Methods must be used, one for calculating the sum of the 5 digits

+5
Answers (1)
  1. 10 August, 11:29
    0
    public class num1 {

    public static void main (String[] args) {

    //Calling the method Calculate

    calculate ();

    }

    //Method Calculate

    public static void calculate () {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter five numbers greater than 0");

    int sum = 0;

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

    System. out. println ("Enter the " + (i+1) + " number");

    sum+=in. nextInt ();

    }

    System. out. println ("The sum of the five numbers is: "+sum);

    }

    }

    Explanation:

    Two Methods are created in Java Programming Language The main method and the method calculate () The calculate method uses a for loop to request users to enter five numbers Every number entered is added to the sum initially set to 0 The sum is printed at the end In the main method, calculate is called.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program must use ...” 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