Question

In: Computer Science

Complete the following Java code. Compute the average of all the numbers in nums and store...

Complete the following Java code. Compute the average of all the numbers in nums and store it in a variable called average

     public static void main(String[] args){

                        int[] nums = <some array values>;

Solutions

Expert Solution

Screenshot :-

Code:-

public class Main
{
   public static void main(String[] args) {
       int[] nums = {3,4,8,9,7};
       float avg=0;
         
       for(int i=0;i<nums.length;i++)
       avg=avg + nums[i];
      
       avg= avg/nums.length;
         
       System.out.println("The average is :" + avg);
   }
}


Related Solutions

Complete the following Java-like pseudocode. Your code should multiply all the numbers in nums and store...
Complete the following Java-like pseudocode. Your code should multiply all the numbers in nums and store it in a variable called mult      public static void main(String[] args){                         int[] nums = <some array values>;
Provide the Java code to compute the sum, average, maximum number and minimum number if I...
Provide the Java code to compute the sum, average, maximum number and minimum number if I have a string sentence of double numbers. Assume that the length of the string sentence is not known. It can be of any length. To split a string based on the comma character use the following. String sentence = "A,B,C,D,E"; String[] stringsArray = receivedSentence.split(","); Then stringsArray is an array of five elements such that: stringsArray[0] = 'A' stringsArray[1] = 'B' stringsArray[2] = 'C' stringsArray[3]...
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
consider the code; typedef struct { int size; int *nums; }Data; Complete the function below that...
consider the code; typedef struct { int size; int *nums; }Data; Complete the function below that creates and returns a new data type that contains a nums array with size randomly chosen integers. Ensure proper error checking. Data *getRandomData(int size) { //PUT CODE HERE //Create random ints for(int i=0; i<size; i++) d->nums[1] = (int)(rand()/(float)RAND_MAX*100); return d;
Write a java code to find the following. For numbers 501 to 999, how many numbers...
Write a java code to find the following. For numbers 501 to 999, how many numbers will have the sum of the digits equal to 10. 501, sum of digits=6 502, sum of digits=7 503, sum of digits=8 504, sum of digits=9 505, sum of digits=10 506, sum of digits=11
Compute ?(?) for the following random variable ?: ?=Number of tosses until all 10 numbers are...
Compute ?(?) for the following random variable ?: ?=Number of tosses until all 10 numbers are seen (including the last toss) by tossing a fair 10-sided die. To answer this, we will use induction and follow the steps below: Let ?(?) be the expected number of additional tosses until all 10 numbers are seen (including the last toss) given ? distinct numbers have already been seen. 1. Find ?(10). ?(10)=? 2. Write down a relation between ?(?) and ?(?+1). Answer...
Methods – Compute Grade Please write a complete Java program, given the following information about (a...
Methods – Compute Grade Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%
The centered average of a list of numbers is the arithmetic mean of all the numbers...
The centered average of a list of numbers is the arithmetic mean of all the numbers in the list, except for the smallest and largest values. If the list has multiple copies of the smallest or largest values, only one copy is ignored when calculating the mean. For example, given the list [1, 1, 5, 3 5, 10, 8, 7], one 1 and 10 are ignored, and the centered average is the mean of the remaining values; that is, 5.2....
Write assembly instructions that compute the following: The sum of all even numbers between 2 and...
Write assembly instructions that compute the following: The sum of all even numbers between 2 and 100 (inclusive) -- the answer should be 2550 Prompt the user for 2 values, put them in variables a and b, then find the sum of all odd numbers between a and b. The sum of all the squares between 1 and 100 (inclusive) . -- the answer should be 338350 All of the statements above should print the answers using print_int MUST BE...
Using the provided Java program, complete the code to do the following. You may need to...
Using the provided Java program, complete the code to do the following. You may need to create other data items than what is listed for this assignment. The changes to the methods are listed in the comments above the method names. TODO comments exist. Apply any TODO tasks and remove the TODO comments when complete. Modify the method findMyCurrency() to do the following:    a. Use a do-while loop b. Prompt for a currency to find. c. Inside this loop,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT