Ask 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 scanner for input of the 5 digits. Two Methods must be used, one for calculating the sum of the 5 digits

+1
Answers (1)
  1. 16 January, 22: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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers