 Java Problems: Euclidean Distance and Arrays

Subject Computer Science Java Programming

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

Java Problems: Recursion, Series & Pairs of Unique Colors \$40.00
Java
Programming
Computer Science
Series
Recursion
Loops
Conditions
Pair of Unique Colors
GUI
Matrix Problem in Java \$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
Java Programming: Nested Statements, Grid of Numbers & Binary Integers \$20.00
Java
Programming
Computer Science
Grid of Numbers
Nested Statements
Loops
Binary Integers
Codes
Conversions
Input
Output
Java Programming Assignment \$25.00
Java Programming
Integers
Pull Numbers
Middle Digit
Rounding
Code
Wordlist Generator in Java (Using OOP) \$125.00
Java
Programming
OOP
Wordlist Generator
Inheritance
Polymorphism
Arrays
String Class Methods
Charlist
Input
Output
Statements
Variables
Loops
Conditions
Live Chats