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]...
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
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...
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%
please write a java code, one for method and another for the Demo to: -Compute the...
please write a java code, one for method and another for the Demo to: -Compute the average age of all female students. -Compute the least amount of credits completed among males. Store the three arrays in the demo file. Print the results within the demo file. String []gender ={"F", "F", "M", "F", "F", "M", "M", "M", "M", "F", "M", "F", "M", "F", "F", "M", "M", "F", "M", "F"}; int []age = {18, 19, 19, 21, 20, 18, 24, 19, 21,...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
Code in Java Create a stack class to store integers and implement following methods: 1) void...
Code in Java Create a stack class to store integers and implement following methods: 1) void push(int num): This method will push an integer to the top of the stack. 2) int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3) void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT