In Java write a program Named class Number Operations. In this class: (a) Create
ID: 3779104 • Letter: I
Question
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.
}
Explanation / Answer
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.