Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA /** * It has two examples of methods for scaling a numeric array. * The task is to: * 1. Describe the difference between

JAVA

/**

* It has two examples of methods for scaling a numeric array.

* The task is to:

* 1. Describe the difference between the scale1 and scale2 methods in at most two sentences.

* 2. Identify which one accurately scales the array and explain why.

*/

public class ArrayScale {

public static void scale1(double[] data, double factor) {

for (double val : data)

val *= factor;

}

public static void scale2(double[] data, double factor) {

for (int j=0; j < data.length; j++)

data[j] *= factor;

}

/**

* Print method that uses StringBuilder to display every element of an array

* @param data

*/

public static void print(double[] data) {

StringBuilder sb = new StringBuilder();

for (double val : data)

sb.append(" " + val);

sb.append(" ");

System.out.println(sb);

}

public static void main(String[] args) {

double[] sample = {1.0, 2.0, 3.0, 4.0};

print(sample);

scale1(sample, 2);

print(sample);

scale2(sample, 3);

print(sample);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

LO4 List options for development needs analyses.

Answered: 1 week ago