Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program mus t use scanner for input of the 5 digits. Two Methods must be used, one for calculating the sum of the 5 digits
1 answer:
Answer:
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.
You might be interested in
Answer:
int x = 10;
Explanation:
This would work in many languages (C/C++/C#/Java).
558c::d367:7c8e:1216:0:66be
Answer:
i dont know how to answer may module because i dont have helper
Answer:
See attached file for detailed code.
Explanation:
See attached file.
Answer:
Client Server Network ... is the central computer that enables authorized users to access networked resources ... computers in this type of network are connected to a central hub ... why might a business choose a server based network (3) ... 2) easier to expand ... external hardware connected to and controlled by a computer.
Explanation: