Posts

Showing posts with the label array of integer

mathajax

Java Lambda Expression - Aggregation

Image
A lambda expression is an anonymous function which performs arithmetic or relational operation over an array of data in sequential or parallel manner . It replaces for-loop like operation over array objects. lambda expression Stream Object The array of data might be a java primitive data type (integer or long or double) or a java collection object (ArrayList). In order to execute the lambda expression over array of data , we need a Stream object ( IntStream, LongStream or DoubleStream ). The Stream object can be obtained by many ways, however, an example shown here. An array variable X initialized with random integers int X [] = { 48, 21, 23, 45, 53, 14, 18, 34, 11, 19,21,23,53 }; IntStream object is obtained by passing X as a argument to Arrays.stream function. IntStream intstream =Arrays.stream(X) An array variable X2 initialized with random integers double X2 [...

Subset on Array of Integers

The java program finds an integer subset by searching on array of integers based on condition and a value. The class Data4 defined the following three member function for search on dataset,integer arrays. they are, 1. greater 2. lesser 3. range and Object of class Data4 is initialized with 20 randomly integers generated from random object with limit range of value [0-1000]. greater function The function greater is invoked by object of Data4 with one integer argument and returns list (array) of integer which are greater than given argument value. lesser function The function greater is invoked by object of Data4 with one integer argument and returns list (array) of integer which are lesser than given argument value. range function The function greater invoked is by object of Data4 with two integer arguments. The second argument is greater than first one. The function returns list of integers which are ...

Maximum value and Index

The java code find a maximum value and its index from array of data A class Data2 has defined with two member functions named max and maxIndex to find maximum value and its index respectively. A object is created to the class,Data with array of integers which are randomly generated from random object. The random generated integer values limited to 1000. pseudocode of find maximum value Read N integer data set maxvaue = 0 for n=0 to N-1 check data[n] > maxvalue maxvalue = data[n] end for print maxvalue pseudocode of find maximum value index Read N integer data set mindex =0 set maxvaue = 0 for n=0 to N-1 check data[n] > maxvalue maxvalue = data[n] mindex = n end for print mindex package cljavabasics; import java.util.Arrays; import java.util.Random; public class ...

Minimum value and Index

The java code find a minimum value and its index from array of data A class Data has defined with two member functions named min and minIndex to find minimum value and its index. A object is created to the class Data with array of integers which are randomly generated from random object. The random generated integer values limited to 1000. Data are generated from randomly using java Random class pseudocode of find minimum value Read N integer data set minvaue = MAX for n=0 to N-1 check data[n] < minvalue minvalue = data[n] end for print minvalue pseudocode of find minimum value index Read N integer data set mindex =0 set minvaue = MAX for n=0 to N-1 check data[n] < minvalue minvalue = data[n] mindex = n end for print mindex import java.util.Arrays; import java.util...

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   ...