Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that takes 10 integer inputs from the user via keyboard and puts

ID: 3843961 • Letter: W

Question

Write a program that takes 10 integer inputs from the user via keyboard and puts them in one array called myNums[], then prints them back out one at a time in this format: Number 1: 55, and finally, computes the sum of these numbers and displays that in this format: Total sum: 922. Condition: The printing of the numbers and the calculation/printing of the sum MUST BE done with 2 functions, respectively, in which you pass the entire myNums array. Print out your program and staple it to this homework.

Explanation / Answer

The java program to accept 10 integer inputs from the use and put them in an array and computing the sum

of the ginve numbers.

import java.util.*; // import package
public class NumberSum
{
   public static void main(String []arg)
   {
       Scanner in = new Scanner(System.in); //Scanner class object to read values from keyboard
  
       int myNums[]= new int[10]; //integer array to accept 10 integer values
       for(int index=0;index<myNums.length;index++)
       {
           myNums[index]=in.nextInt(); // storing or putting integers in the array
       }
       int c=1;
       for(int index=0;index<myNums.length;index++)
       {
           System.out.println("Number "+c+":"+myNums[index]);//printing values in the given array
           c++;
       }
       int sum=calSum(myNums); // function to calculate sum of the given numbers
       System.out.println("Total Sum:"+sum); //printing sum of the given numbers
      
   }

   private static int calSum(int[] myNums) //funcion implements
   {
       int sum=0;
       for(int index=0;index<myNums.length;index++)
       {
           sum=sum+myNums[index];  
       }
       return sum; //it return sum of the given numbers
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote