Question

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 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]);
}
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Matrix Problem in Java
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
Wordlist Generator in Java (Using OOP)
Homework Solution
$125.00
Java
Programming
OOP
Wordlist Generator
Inheritance
Polymorphism
Arrays
String Class Methods
Charlist
Input
Output
Statements
Variables
Loops
Conditions
Get help from a qualified tutor
Live Chats