Write a main class with a main method that tests your method

Assignment Help JAVA Programming
Reference no: EM131028324

Question 1. Write static methods as follows:

• double sum(double[] a) - returns the sum of the entries in the array a.

• double[] fill(int n, double v) - returns an array of n doubles, all of whose values are v.

• double[] random (int n) - return an array of n random doubles.

• double min(double[] a) - returns the minimum element of the array a.

• double max(double[] a) - returns the maximum element of the array a.

• double average(double[] a) - returns the average (or mean) of the elements of the array a.

• double variance(double[] a) - returns the variance of the elements of the array a (note: this method should call your average method).

• double stdDev(double[] a) - returns the standard deviation of the elements of the array a (note: this method should call your variance method).

• double[] read() - reads an array from the keyboard and returns it (read the number of elements first, and then that many numbers).

• void print(double[] a) - prints an array, a, on a single line with commas between elements (do NOT use Arrays.toString()).

Write a Main class with a main method that tests your methods appropriately (i.e. by calling each method at least once with various inputs), and printing the results.

Question 2. Consider the following method and method call:

public static int inc(int a) {

a++;

return a;

}

int a = 10;

int b = inc(a + 12);

int c = inc(a);

System.out.println(a);

System.out.println(b);

System.out.println(c);

What is the output from this code? Carefully explain your answer (i.e. carefully show how the method

inc is called).

Question 3. Consider the following method and method call:

public static int[] inc(int[] a) {

a[0]++;

return a;

}

int[] a = { 10, 20, 30, 40 };

int[] b = inc(a);

System.out.println(b[0]);

System.out.println(a[0]);

What is the output from this code? Carefully explain your answer (i.e. carefully show how the method

inc is called).

Question 4. Consider the following code:

int[] a = { 10, 20, 30, 40 };

int[] b = a;

int[] c = { 10, 20, 30, 40 };

System.out.println(a == b);

System.out.println(a == c);

What is the output from this code? Carefully explain your answer.

Reference no: EM131028324

Questions Cloud

How many choices are possible to find solution : If who selected which choice is ignored (as a chef would). Analyze this part by the number of different choices made.
Build an application based upon temperature converter app : e purpose of this assignment to confirm that sub routines and functions can be used within Visual Basic programs. Build an application based upon the Temperature Converter application demonstrated in this week's Presentation.
How is political independence embedded in role of fed chair : An article in the Wall Street Journal commented that despite Perry's remarks: " Bernanke is willing to embrace the political independence embedded in his role to do what Fed officials think the economy needs." How is "political independence" embed..
Constructor functions for your button events : constructor functions for your button events as outlined. This application simulates a vending machine that dispenses soft drinks.
Write a main class with a main method that tests your method : Write a Main class with a main method that tests your methods appropriately (i.e. by calling each method at least once with various inputs), and printing the results.
How the statistical devices can be used in business : How the following statistical devices can be used in business today? Describe their usefulness and how businessman can be benefit, or how to help them in making sound decisions. (Explain individually)
How many distinct ways can the assignments be made : Once all of the students have had their training, they will be assigned to 3 teams with 4 workers on each team and team duties will be assigned.
How many different orders can the song be arranged : A disk jockey can play 7 songs during his program. If there are 13 songs to chose from, in how many different orders can the song be arranged?
Statements for kohls corporation for the 2010 fiscal year : Financial statements for Kohl's Corporation for the 2010 fiscal year ending January 29, 2011. Under the term Groupings Filter, change the term All Forms to Annual Filings using the drop-down arrow and press Search.

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Algorithm analysis with advanced data structures

Algorithm Analysis with Advanced Data Structures, Your good friend, a Rock Star, asked you to create a Time Manager app for him, The Rock Star performs gigs at certain dates, all around the country - at most one gig per day

  Create a 2d array of randomly generated ints

Write a complete Java class that will create a 2D array of randomly generated ints that of size 5 rows and 10 columns. Print the values of each cell to a 5x10 table.

  Problem aa savings account object holds a nonnegative

problem aa savings account object holds a nonnegative balance and provides depositk and withdrawk methods where

  Design a java application using the list data structure

You are to design a Java application using the list data structure to manage your contact information. Each contact may have the subsequent data:

  Dangerousmonster which inherits the monster

An interface - DangerousMonster which inherits the Monster interface and has a method called destroy() with void return type.(Note: Just like a class can inherit from another class, an interface can inherit from another interface using the "extends..

  Following names with an associated phrase

Name game (8 points). Match the following names with an associated phrase. Use each letter once and only once. A. Steve Cook _______ Incompleteness B. Alan Turing _______ Reductions

  Questions1 write a programme that computes the rental

questions1. write a programme that computes the rental charge given the type of moped when it is rented weekday or

  Find factors of a given number

Write a java program to find factors of a given number.

  Create a splash screen for the tgc application

To complete your splash screen please use the information below: Create a splash screen for the TGC application that displays: the application's name.

  How many bits are needed to represent the index size

How many bits are needed to represent the index size - what would be the index size if 8-way set associative cache were used with the same capacity and block size?

  These are more specialized versions of the pizzaorders you

your pizza shop expands and now handles delivery orders and sit down orders in a restaurant setting. there are

  Represent the relationship between parents - children class

Draw a class diagram that represents the relationship between parents, children, and grandparents. Take into account that a person can have both a parent and a child. Annotate associations with roles and multiplicities.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd