In Java write a program Named class Number Operations In thi
In Java write a program Named class Number Operations.
In this class:
(a) Create a method to sum up the integers as:
public static void sumUp(int [] numbers){
}
This method should take in an integer array and total the numbers.
In your main method create an array of five integers, next fill it with 5 integers.
public static void main(String[]args){
Scanner key = new Scanner (System.in);
//Write required code to add five numbers to this array now.
//Now call the Procedure to add the five numbers.
}
Solution
NumberOperations.java
import java.util.Scanner;
public class NumberOperations {
public static void main(String[]args){
Scanner key = new Scanner (System.in);
//Write required code to add five numbers to this array now.
int numbers[] = new int[5];
//Now call the Procedure to add the five numbers.
for(int i=0; i<numbers.length; i++){
System.out.print(\"Enter the number: \");
numbers[i] = key.nextInt();
}
sumUp(numbers);
}
public static void sumUp(int [] numbers){
int sum = 0;
for(int i=0; i<numbers.length; i++){
sum = sum + numbers[i];
}
System.out.println(\"Sum is \"+sum);
}
}
Output:
Enter the number: 1
2Enter the number:
Enter the number: 3
Enter the number: 4
Enter the number: 5
Sum is 15
![In Java write a program Named class Number Operations. In this class: (a) Create a method to sum up the integers as: public static void sumUp(int [] numbers){ } In Java write a program Named class Number Operations. In this class: (a) Create a method to sum up the integers as: public static void sumUp(int [] numbers){ }](/WebImages/41/in-java-write-a-program-named-class-number-operations-in-thi-1127901-1761601862-0.webp)
![In Java write a program Named class Number Operations. In this class: (a) Create a method to sum up the integers as: public static void sumUp(int [] numbers){ } In Java write a program Named class Number Operations. In this class: (a) Create a method to sum up the integers as: public static void sumUp(int [] numbers){ }](/WebImages/41/in-java-write-a-program-named-class-number-operations-in-thi-1127901-1761601862-1.webp)