Posts

Showing posts with the label int array

mathajax

Chebyshev distance between two points

Image
The java program finds distance between two points using chebyshev distance equation . The points can be a scalar or a vector . 1D distance metric It measures distance between two points by absolute difference between them. Each point has one element. 2-Dimensional distance metric It measures distance between two points (2D vector) by selecting maximum absolute difference on 2D vector element absolute difference. N-Dimensional distance metric It measures distance between two N-Dimensional vector by selecting maximum absolute difference on the two N-D vector element. Example Calculation on 2D vectors This is an example calculation shown below explain how to find the distance between two vectors using Chebyshev distance formula. A vector,array of elements declared and initialized in Java using one dimensional array. int A[] = { 2 ,6 }; // 2D vector A int B[] = { 4,1 }; // 2D vector B max - operators finds greatest val...

Metric - Minkowski distance between two points

Image
The java program finds distance between two points using minkowski distance equation . when power is set P=1, minkowski metric results as same as manhattan distance equation and when set P=2, minkowski metric results as same as euclidean distance equation. 1-Dimensional distance It measures the distance between two points . Each point lies on a line and has one element. 2-Dimensional distance It measures the distance between two points. Each point lies on 2D cartesian plane and has 2 elements. N-Dimensional distance It measures the distance between two points and each point has N elements. Example Calculation This is an example calculation shown below explain how to find the distance between two vectors using Minkowski distance formula . A vector,array of elements declared and initialized in java using one dimensional array. int A[] = { 5 ,3 }; // 2D vector A int B[] = { 2,1 }; // 2D vector B int P =3; P th ...

Metric - Manhattan Distance between two points

Image
The java program finds distance between two points using manhattan distance equation.  The points can be a scalar or vector and the passed to function as arguments can be integer or double datatype. 1D distance between two points It measures distance between two points on a line (1D) by absolute difference between them and the points are scalar value. Two points on 2D cartesian space It measures distance between two points on a plane. The points are vectors and each has two elements. The resulting distance equals sum of the difference of each element on the vectors . Two points on N-Dimensional cartesian space It measures d istance between two points or vectors on N-dimensional space . The points are vectors and each has N elements.The resulting distance equals sum of the difference of each element on the vectors. This is an example calculation shown below explain how to find the distance between two vectors using Manhat...

Java program Sum of Array Integers

Image
The java program find sum of  integers.       Pseudocode of sum of integer  set sum =0 Read an integer N initialize integer array size of N for n= 0  to N-1       Read an integer data      store data into array end for      for each E  in  array      sum = sum + E end each print sum Java keywords and objects usage in the program BufferedReader class object : provides stream mechanism to read inputs from user/keyboard Integer class object : converts string object into java primitive datatype int for-loop :- repeats reading inputs from user upto N times for-each  : to read element from array in sequential order  import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SumofArrayNumber { public static void main(String[] args) throws IOException   ...

Java program Biggest number among N Integers

In order to f ind biggest number from unordered (not sorted) set of N numbers , a sequential search mechanism used, in which search starts from zero index to N-1 index. A Biggest number from array numbers - Pseudocode Read a integer N initialize memory array of N element Read integers and store into an array set biggest = 0; for n=0 to N check array[n] > biggest , set biggest = array[n] end for print biggest A Biggest number from array of numbers - Java program The Java program read N integers from user via keyboard and stored on an array. It has a for-loop to start sequential search to find a biggest number from this array of numbers . import java.io.IOException; import java.util.Scanner; public class BiggestAmongN { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); System.out.println( "Enter Number of Eleme...