QuestionQuestion

Problem 1. (Euclidean Distance) Implement a program Distance that computes and prints the Euclidean distance between two vectors x and y represented as one-dimensional arrays of double values. The distance is calculated as the square root of the sums of the squares of the diļ¬€erences between corresponding entries. Your code should work for vectors of any length.
$ java Distance
13.0

Problem 2. (Reversing an Array) Implement a program Reverse that reverses a one dimensional array a of String values and prints the reversed array. Do not create another array to hold the result. Hint: Use the code in the text for exchanging two elements.
$ java Reverse
question
the
is
that
,
be
to
not
or
,
be
to

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Reverse {

public static void main(String[] args)
{
String words[] = {"To", "be", "or", "not", "to", "be", "that", "is", "the", "question"};

for(int i = 0; i < words.length/2; i++)
{
String temp = words[i];
words[i] = words[words.length-(i+1)];
words[words.length-(i+1)] = temp;
}

for(int i = 0; i < words.length; i++)
System.out.println(words[i]);
}
}...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats