Ask Question
27 August, 23:40

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. 28 August, 03:25
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers