Skip to content

In this repository are located solutions to tasks written in the Java programming language of using onedimensional and multidimensional arrays. A more detailed description of the project structure and the conditions of the tasks can be found in the file README.md .

Notifications You must be signed in to change notification settings

KostiantynLuhovyi/java-arrays.tasks-solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 

Repository files navigation

java-arrays.tasks-solution

In this repository are located solutions to tasks written in the Java programming language of using onedimensional and multidimensional arrays.

Names of packages with classes that solve a task have a brief description of the task to be solved. The description of the tasks to be solved can be read in the comments in the Main class, which is in each package with the tasks to be solved. Also in the file README.md.

Many of functional solutions are implemented in the java-helper library classes. A detailed description of the functional contained in the library "java-helper" and used for solving tasks can be found in the repository by the link: https://github.com/LugowoyKonstantin/java-helper.tasks-solution

If you have any questions about this repository or the solution of the tasks in it, you can contact the following contacts:

email: kostya.lugowoy@gmail.com
skype: Lugowoy Konstantin
linkedin: Konstantin Lugowoy
facebook: Konstantin Lugowoy


The package name and description of the solved task that are contained in the root package com.lugowoy.tasks :

  • multidimensional
    • buildMatrixSubtractingFromElementsOfEachRowOfMatrixItsArithmeticAverage
      • Build a matrix, subtracting from the elements of each row of the matrix its arithmetic average.
    • calculateMatrixDeterminant
      • Calculate the matrix determinant.
    • calculateMatrixNorms
      • Calculate the matrix norms.
    • compressMatrixByRemovingRowsAndColumnsFilledWithZerosFromIt
      • Compact the matrix by removing rows and columns filled with zeros from it.
    • constructPascalTriangle
      • Write a program that builds a Pascal triangle to a depth of 12. Each number of a triangle is stored in an array of the appropriate length, and the array of rows is stored in an array, the elements of which are 12 arrays of type int.
    • convertRowsOfMatrixSoThatElementsEqualToZeroLocatedAfterAllOthers
      • Convert the rows of the matrix so that the elements equal to zero are located after all the others.
    • findAllLocalMaximumsOfMatrixAndTheirNumber
      • Find all local maximums of the matrix and their number.
    • findAllLocalMinimumsOfMatrixAndTheirNumber
      • Find all local minimums of the matrix and their number.
    • findAndDisplayLargestNumberOfDecreasingElementsOfMatrixGoingInRow
      • Find and display the largest number of decreasing elements of the matrix, going in a row.
    • findAndDisplayLargestNumberOfIncreasingElementsOfMatrixGoingInRow
      • Find and display the largest number of increasing elements of the matrix, going in a row.
    • findNumberOfAllSaddlePointsOfMatrix
      • Find the number of all saddle points of the matrix.
    • findSumOfMatrixElementsLocatedBetweenFirstAndSecondPositiveElementsOfEachRow
      • Find the sum of matrix elements located between the first and second positive elements of each row.
    • firstTaskForFormationOfSquareMatrixAccordingToGivenPattern
      • Form a square matrix of order n according to a given pattern: 1 2 3 … n n n-1 n-2 … 1 1 2 3 … n n n-1 n-2 … 1 … … … … … n n-1 n-2 … 1 (n – even number).
    • moveMinimumMatrixElementToSpecifiedLocationUsingPermutationOfRowsAndColumns
      • Move the minimum matrix element to the specified location using permutation of rows and columns.
    • performCyclicShiftOfGivenMatrixByCertainNumber
      • Perform a cyclic shift of a given matrix by a certain number of positions to the right (left, up, down).
    • rearrangeElementsOfSquareRealMatrixInAscendingOrderAlongDiagonal
      • Rearrange the elements of a square real matrix in ascending order along the diagonal.
    • rearrangeElementsOfSquareRealMatrixInDescendingOrderAlongDiagonal
      • Rearrange the elements of a square real matrix in descending order along the diagonal.
    • rebuildMatrixRearrangingColumnsInItSoThatValuesOfTheirCharacteristicsDecrease
      • Rebuild the given matrix, rearranging the columns in it so that the values of their characteristics decrease.
    • rebuildMatrixRearrangingColumnsInItSoThatValuesOfTheirCharacteristicsIncrease
      • Rebuild the given matrix, rearranging the columns in it so that the values of their characteristics increase.
    • rebuildMatrixRearrangingRowsInItSoThatElementsInRowsOfResultingMatrixAreIncreased
      • Rebuild the matrix, rearranging the rows in it so that the elements in the rows of the resulting matrix are increased.
    • rebuildMatrixRearrangingRowsInItSoThatValuesOfTheirCharacteristicsDecrease
      • Rebuild the given matrix, rearranging the rows in it so that the values of their characteristics decrease.
    • rebuildMatrixRearrangingRowsInItSoThatValuesOfTheirCharacteristicsIncrease
      • Rebuild the given matrix, rearranging the rows in it so that the values of their characteristics increase.
    • removeFromMatrixAllRowsAndColumnsContainingMaximumElement
      • Find the maximum element(s) in the matrix and remove from the matrix all the rows and columns containing it.
    • rotateMatrixByCertainNumberOfDegrees
      • Rotation of the matrix by a certain number of degrees
    • roundAllElementsOfMatrixToInteger
      • Round all elements of the matrix to an integer.
    • secondTaskForFormationOfSquareMatrixAccordingToGivenPattern
      • Form a square matrix of order n according to a given pattern: 0 0 0 … 0 0 1 0 0 0 … 0 2 0 0 0 0 … 3 0 0 … … … … … … … 0 n-1 0 … 0 0 0 n 0 0 … 0 0 0
    • sortColumnsOfMatrixInAscendingOrderOfValuesOfElementsOfKthRow
      • Sort the columns in ascending order of values of the elements of k-th row.
    • sortColumnsOfMatrixInDescendingOrderOfValuesOfElementsOfKthRow
      • Sort the columns in descending order of values of the elements of k-th row.
        ...
    • thirdTaskForFormationOfSquareMatrixAccordingToGivenPattern
      • Form a square matrix of order n according to a given pattern:
        n 0 0 … 0 0 0
        0 n-1 0 … 0 0 0
        0 0 n-2 … 0 0 0
        … … … … … … …
        0 0 0 … 0 2 0
        0 0 0 … 0 0 1
  • onedimensional
    • calculateSumOfArrayElementsLocatedBetweenMinAndMaxElementsInclusive
      • Given an array of numbers. Calculate the sum of array elements located between the minimum and maximum elements inclusive.
    • calculateSumOfMaxAndMinElementOfThisParticularSequence
      • Given dimensional array A[n]. Find: max(a2, a4, ..., a2k) + min(a1, a3, ..., a2k-1).
    • changeSequenceByMultiplyingElementsBySquareOfMinAndMaxNumbersByRule
      • Given integers a1, a2, ..., an. It is required to multiply all the terms of the sequence a1, a2, ... by the square of its smallest term, if ak ≥ 0, and the square of its largest term, if ak ≤ 0.
    • compareMultiplicationModulesOfPositiveAndNegativeNumbers
      • In the sequence of integers a1, a2, ..., an, there are positive and negative elements. Calculate the multiplication of negative elements P1 and the multiplication of positive elements P2. Compare the module P2 with the module P1 and indicate which of the products is larger modulo.
    • compressArrayByThrowingEverySecondElement
      • Given an array with the number of n elements. "Squeeze" the array, throwing out every second element from it.
    • compressArrayByThrowingOutZeroValueElements
      • An array containing integers is specified. Compress it, throwing out the zero elements.
    • convertSecondSequenceAccordingToRuleDefinedByFirstSequence
      • Given integers a1, a2, ..., an and b1, b2, ..., bn. Convert the sequence bl, b2, ..., bn by the rule: if ai ≤ 0, then bi is increased by a factor of 10, otherwise bi is replaced by zero.
    • countApplicantsWithAssessmentIsNotAllowedForSecondExam
      • On admission to university entrants who have received "two" in the first exam, the second is not allowed. The array A[n] written assessment exams obtained in the first test. Calculate how much a person is not admitted to the second exam.
    • countingNumberOfPeopleWhoseAgeIsInGivenInterval
      • Write a program whose input is the age of n people. The program counting the number of people whose age is in the specified interval.
    • countOfPositiveAndNegativeAndZeroElementsInArray
      • Given an array of integer numbers, whose dimension is N. Calculate how much it negative, positive and zero elements.
    • createArrayOfEvenNumbersBasedOnAnotherArray
      • Given a array of positive numbers a1, a2, ..., an. Create an array of even numbers of this array.
    • createArrayOfZeroElementsOfAnotherArray
      • There are zero elements in an integer array. Create an array of the index of these elements.
    • createNewArrayFromUniqueElementsOfOriginalArray
      • Given a one-dimensional array of numbers, among the elements of which are the same. Create a new array from the various elements of the original array.
    • createNewArrayWhoseElementsWillBeElementsOfSourceEndingInSpecificNumber
      • An array of n natural numbers is given. Create a new array, the elements of which will be elements of the source, ending in a specific number.
    • createOrderedArrayFromElementsOfTwoOtherOrderedArrays
      • Given two ordered arrays A and B. Form from the elements of these arrays an ordered array C.
    • cyclicallyShiftElementsOfArrayElementsToRightOrLeft
      • Given an array A. Cyclically shift the elements of the array to K elements to the right (to the left).
    • determineElementsThatAreEqualToHalfSumOfNeighboringElements
      • Determine the elements that are equal to the half-sum of the neighboring elements.
    • determineEquilibriumBetweenWeightOfSubjects
      • Write a program that enter a sequence of integers that counts them as the masses of objects available and finds out whether all these items can be put on two cups of the weighing-machine so that achieve balance.
    • determineGreatestCommonDivisorForArrayOfNumbers
      • Write a program that enter a sequence of integers that finds and prints their greatest common divisor.
    • determineIndexOfPrimeNumbersInArray
      • The integer array of dimension of N is set. Whether there are among array elements prime numbers? If yes, that to output index numbers of these elements.
    • determineLeastCommonMultipleOfArrayOfNumbers
      • Write a program that enter an array of integers, finds and prints their least common multiple a number.
    • determineMaxRadiusOfCircleWithCenterAtOriginWhichContainsAllPoints
      • In a one-dimensional array with an even number of elements (2N) there are coordinates of N points of the plane. They are arranged in the following order: x1, y1, x2, y2, x3, y3, etc. Determine the maximal radius of the circle with the center at the origin, which contains all the points.
    • determineMostRepeatedElementInArray
      • In the array of integers with the number of elements n, find the most repeated number. If there are several such numbers, then determine the smallest of them.
    • determineNumberOfArrayInWhichRemainderOfDivisionIsEqualToCertainNumber
      • Determine the number of the array in which the number is equal to dividing a certain number.
    • determineNumberOfDifferentElementsInOneDimensionalArray
      • Given a one-dimensional array of numbers. Find the number of different numbers in this array.
    • determineNumberOfElementsThatAreIdenticalInTwoSequences
      • Two sequences of integers a1, a2, ..., an and b1, b2, ..., bm are given. All the members of the sequences are distinct numbers. Find how many elements of the first sequence coincide with the elements of the second sequence.
    • determineNumberOfLocalMaximalInArray
      • Write a program that enter a non-empty array of integers and prints the number of local maxima (an element is a local maximum if it has neighbors elements larger than itself).
    • determineNumberOfPairsOfPointsDistanceBetweenWhichIsMaximally
      • The coordinates of n points on the plane are given: (X1, Y2), ..., (Xn, Yn) (n ≤ 40). Find the number of pairs of points, the distance between which is maximally (assume that such a pair is unique).
    • determineNumberWithEvenIndexesIfThereIsNumberWithOddIndexForHim
      • Write a program that enter a sequence of integers and prints numbers with even indexes if there is an equal number with an odd index.
    • determinePairsOfNumbersFromSequenceWhoseSumIsEqualToEnteredNumber
      • Given a sequence of integers a1, a2, ..., an. Indicate pairs of numbers ai, aj such that ai + aj = m.
    • determineRingWithCenterAtOriginWhichContainsAllPoints
      • In a one-dimensional array with an even number of elements (2N) there are coordinates of N points of the plane. They are arranged in the following order: x1, y1, x2, y2, x3, y3, etc. Define a ring with center at the origin, which contains all points.
    • determineSequenceOfNumbersIsIncreasing
      • Given a sequence of integer numbers a1, a2, ..., an. Determine whether it is increasing.
    • determineTimeOfStayOfCustomerInQueue
      • At the counter of the store, a line of n customers lined up. The service time of the i-th customer is tj (i = 1, ..., n). Determine the time Ci of the stay of the i-th customer in the queue.
    • determineTriangleForWhichDifferenceInNumberOfPointsOutsideAndInsideIsMinimal
      • In a one-dimensional array with an even number of elements (2N) there are coordinates of N points of the plane. They are arranged in the following order: x1, y1, x2, y2, x3, y3, etc. Identify three points that are the vertices of a triangle for which the difference in the number of points outside it and inside is minimal.
    • determineWhetherElementsOfSecondSequenceInFirstSequence
      • Two sequences a1, a2, ..., an and b1, b2, ..., bm (m <n) are given. In each of them, the members are different. Is it true that all members of the second sequence are in the first sequence?
    • determineWhetherItIsPossibleToSelectContiguousElementsInOneOfArraysByCondition
      • Two integer arrays are given. Determine whether in the first of them one can choose k consecutive elements Xj, Xj + 1, ..., Xk-1, so that Xj = Y1, Xj + 1 = Y2, ..., Xk-1 = Yk.
    • divideOriginalArrayInToEvenAndOddArray
      • Given an array with the number of elements of N. Form two arrays: the first include elements of the original array with even numbers, and in the second - with odd numbers.
    • findIndicesOfMostRemoteAndLeastDistantPoints
      • In a one-dimensional array with an even number of elements (2N) there are coordinates of N points of the plane. They are arranged in the following order: x1, y1, x2, y2, x3, y3, etc. Find the numbers of the most distant points and the points that are the least distant from each other.
    • findLengthOfLongestSawtoothSequenceOfSuccessiveNumbers
      • Find the length of the longest "sawtooth" sequence of successive numbers Xk <Xk + 1> Xk + 2> ...> Xk + m <Xk + m + 1 <... <Xn.
    • findLengthOfLongestSequenceOfElementsEqualToZero
      • Given an array A. Find the length of the longest sequence of consecutive array elements equal to zero.
    • findNumbersInSequenceThatAreSquareOfNumber
      • Given positive integers a1, a2, a3, ..., an. Find among them those whose square is equal to a certain number n.
    • findSegmentOfArrayIsPolindrome
      • Given an array A. Find the segment of the maximum length array in which the first number equals the last, the second the penultimate, and so on. Output this segment and its length.
    • findSubsetOfContiguousElementsOfArraySumOfValuesOfElementsWhichIsEqualToNumber
      • Find subset of contiguous elements of array sum of values of elements which is equal to number.
    • findSumOfArrayOfMultipleElementsToThisPresent
      • Given an array of numbers. Find the sum of the elements that are multiples of to this K.
    • findTwoNumbersWhoseArithmeticMeanIsClosestToNumberEntered
      • Given a real number x and an array A [n]. In the array, find two members whose arithmetic mean is closest to x.
    • getIntegersInAscendingOrderThatDoesNotBelongToThisArray
      • Given an array of integers. Find in this array element N minimum and maximum element M. Get in ascending order of all the integers from the interval (N; M), which are not included in this array.
    • insertAnIntegerInSequencePositionWithoutViolatingIncrease
      • Given a sequence of integers a1 ≤ a2 ≤ ... ≤ an. Insert an integer b into it so that the sequence remains non-decreasing.
    • interchangedMaximumAndMinimumElementOfArray
      • Given integer numbers a1, a2, ..., an. Interchange the maximum and minimum elements.
    • interchangeElementsStandingOnOddAndEvenPositionsInArray
      • The specified one-dimensional array interchange the adjacent elements standing on even places, with standing on the odd elements.
    • locateSnailOnTreeAfterThirtyDays
      • Every sunny day, a snail sitting on a tree climbs up 2 cm, and each cloudy day drops down by 1 cm. At the beginning of observation, the snail is A cm from the ground on a B-meter tree. There is a 30-element array containing information about whether the corresponding observation day was cloudy or sunny. Write a program that determines the location of the cochlea at the end of the 30th day of observation.
    • numberOfPreviouslyFoundPositiveOrNegative
      • The sequence of numbers a1, a2, ..., an. To find out what number is found before - positive or negative.
    • openLockOnDoorByLookingThroughPlayingDice
      • The secret lock for the safe consists of 10 cells arranged in a row, into which it is necessary to insert the playing dice. But the door is opened only if in any three neighboring cells the sum of the points on the front faces of the cubes is 10. (The dice has 1 to 6 dots on each face.) Write a program that unravels the lock code, provided that two dice already inserted in the cells.
    • outputElementsIncludedInInterval
      • Given a sequence of integer numbers a1, a2, ..., an. Output elements of it that belong to the interval [c, d].
    • outputElementsOfIndexesWhichAreDegreeOfTwo
      • Given an array with the number of n elements. Print those elements whose indices are degree of two (1, 2, 4, 8, 16, ...).
    • outputElementsOneDimensionalArrayAsArgumentsAndAssociatedValues
      • In the one-dimensional array are placed: in the first elements of the value of the argument, in the following - the corresponding values of the function. Print the elements of array n parallel columns (argument and function value).
    • outputNumbersForWhichSumOfFirstTwoDigitsIsEqualToSumOfLastTwo
      • An array of n four-digit natural numbers is given. Output to display only numbers those on which the sum of the first two digits is equal to the sum of the last two digits.
    • outputNumbersFromArrayThatSatisfyConditionForSolutionOfTask
      • Write a program that has an array of random integers and prints three of its (not necessarily distinct) elements x, y, and z, such that x * y = z.
    • outputNumbersUpToAndIncludingZero
      • Given a sequence of numbers. Print out all the numbers up to and including zero.
    • outputToDisplayNumberForParticularCondition
      • Given numbers a1 a2, .... an. Print out only the number, for which the condition ai ≤ i.
    • replaceSmallestNumberInSequenceByArithmeticMeanOfNumbers
      • Given integers a1, a2, ..., an. The smallest member of this sequence is replaced by the integer part of the arithmetic mean of all terms, leaving the remaining terms unchanged. If there are several smaller terms in the sequence, then replace the last one in order.
    • replaceTheArrayNumbersOfLargerZ
      • Given a sequence of integer numbers a1, a2, ..., an. Replace all of its members, of the Z larger, this number. Count the number of substitutions.
    • replaceWithZerosElementsThatAreModuloGreaterThanTheMaximumElement
      • Given integers a1, a2, ..., an. Among them there are positive and negative. Replace the zeros with those numbers that they are more modular than a certain number (| ai |> max {a1, a2, ..., an}).
    • sortArrayConsistingOfZerosOnesAndTwos
      • In the array, each element is 0, 1, 2. Rearrange the elements of the array so that all zeros are first, then all the ones, and finally all the deuces.
    • sortArrayInAscendingOrderWithoutChangingTheirRelativePosition
      • In a one-dimensional array, rearrange the elements so that negative elements are first located, then zero, and then positive. The relative arrangement of the elements does not change.
    • specifySetOfTrianglesWithVerticesAtGivenPointsThatIntersectWithCircle
      • On the n-plane the points are given by their coordinates and a circle of radius R with center at the origin is also given. Specify the set of all triangles with vertices at given points intersecting a circle; The set of all triangles contained inside the circle.

About

In this repository are located solutions to tasks written in the Java programming language of using onedimensional and multidimensional arrays. A more detailed description of the project structure and the conditions of the tasks can be found in the file README.md .

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages