Java

Programming Languages Series

1. Introduction Welcome to our Programming Languages Series! In this series, we’ll explore various programming languages, understand their purposes, provide code examples, and discuss when to use each one.

Read More

Python vs Java Performance: Programming Powerhouses

In the vast landscape of programming languages, Python and Java have emerged as titans, offering robust solutions for a wide range of applications.

Read More

How to learn Java in 1 day

Learning Java in one day is not a realistic goal, as Java is a complex programming language that requires time and practice to master.

Read More

How to Find the nth Reverse Number in Java

The challenge Reverse Number is a number which is the same when reversed.

Read More

How to Find the Sum of Intervals in Java

The challenge Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths.

Read More

How to Compile Multiple Java Files from a Single Command in Java

If you need to compile multiple Java files using a single command, then you can do the following.

Read More

How to Convert JSON to a Java Object

If you need to convert JSON to a Java Object, then you can do one of the following:

Read More

How to Calculate Powers of Integers in Java

If you need to calculate the powers of Integers in Java, then you can do one of the following:

Read More

How to Get Today’s Date in Java

If you need to get today’s date in Java, then you can do one of the following:

Read More

How to Make a Java Jar File Executable

Let’s say you have a Java project as follows: package ms.

Read More

How to Read a File Line by Line in Java

If you need to read a file line by line in Java, then you can use one of the following three (3) options.

Read More

How can I clear or empty a StringBuilder

You can use Java’s StringBuilder to create and manipulate Strings as follows:

Read More

How to Convert Array to String in Java

If you need to convert an array to a string in Java, then you could look at a solution like this:

Read More

How to Base64 Encode a String in Java

Quick solution In short, you can just do this: new String(Base64.

Read More

How to Generate a Random String in Java

Java provides many ways to generate random strings. 1. Using Apache Commons public void generatingRandomAlphanumericString_ApacheCommons() { String generatedString = RandomStringUtils.

Read More

How to Parse HTML/CSS Colors in Java

The challenge In this challenge, you parse RGB colors represented by strings.

Read More

Solving Simple Transposition in Java

The challenge Simple transposition is a basic and simple cryptography technique.

Read More

The Difference of 2 in Java

The challenge The objective is to return all pairs of integers from a given array of integers that have a difference of 2.

Read More

How to Make the Deadfish Swim in Java

The challenge Write a simple parser that will parse and run Deadfish.

Read More

How to Write Number in Expanded Form in Java

The challenge You will be given a number and you will need to return it as a string in Expanded Form.

Read More

Is a Number Prime in Java

The challenge Define a function that takes one integer argument and returns a logical value true or false depending on if the integer is a prime.

Read More

How to Calculate Minutes to Midnight in Java

The challenge Write a function minutesToMidnight(d) that will take a date object as the parameter.

Read More

How to get the Sum of the First nth Term of a Series in Java

The challenge Your task is to write a function that returns the sum of the following series up to nth term(parameter).

Read More

How to Keep up the Hoop in Java

The challenge Alex just got a new hula hoop, he loves it but feels discouraged because his little brother is better than him

Read More

Will there be Enough Space in Java

The challenge Bob is working as a bus driver. However, he has become extremely popular amongst the city’s residents.

Read More

How to Swap Node Pairs In Linked List in Java

The challenge If you are given the head node in a linked list, write a method that swaps each pair of nodes in the list, then returns the head node of the list.

Read More

How to Solve ‘Finding Neo’ in Java

The challenge Neo is somewhere in the Matrix. public interface Matrix { public int size(); public int get(int x, int y); } You are Morpheus, and your job is to find him.

Read More

How to Solve a Pandigital Sequence in Java

The challenge In mathematics, a pandigital number is a number that in a given base has among its significant digits each digit used in the base at least once.

Read More

How to Calculate Transport on Vacation in Java

The challenge After a hard quarter in the office you decide to get some rest on a vacation.

Read More

Playing with the letter ‘E’ in Java

The challenge Given String str, return: If given String doesn’t contain any “e”, return: “There is no “e”.

Read More

The Deaf Rats of Hamelin Challenge in Java

The challenge The Pied Piper has been enlisted to play his magical tune and coax all the rats out of town.

Read More

How to Find the Next Perfect Square in Java

The challenge You might know some pretty large perfect squares. But what about the NEXT one?

Read More

How to Create a Java GUI App that shows the Logged-in User and Hostname

Create a new file called Application.java and paste the following:

Read More

How to Solve Two-Sum in Java

The challenge Write a function that takes an array of numbers (integers for the tests) and a target number.

Read More

How to Sort the Gift Code in Java

The challenge Santa’s senior gift organizer Elf developed a way to represent up to 26 gifts by assigning a unique alphabetical character to each gift.

Read More

How to get the Numericals of a String in Java

You are given an input string. For each symbol in the string if it’s the first character occurrence, replace it with a ‘1’, else replace it with the amount of times you’ve already seen it.

Read More

How to “Dashatize It” in Java

The challenge Given a variable n, If n is an integer, Return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark.

Read More

Comparing Array Multiplicities in Java

The challenge Given two arrays a and b write a function comp(a, b) (orcompSame(a, b)) that checks whether the two arrays have the “same” elements, with the same multiplicities.

Read More

How to Find the Max Tree Node Value in Java

The challenge You are given a binary tree. Implement the method findMax which returns the maximal node value in the tree.

Read More

How to String Search with a Wildcard in Java

The challenge The method below is the most simple string search algorithm.

Read More

Get the Consonant Value in Java

The challenge Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings.

Read More

Word Values Challenge in Java

The challenge Given a string "abc" and assuming that each letter in the string has a value equal to its position in the alphabet, our string will have a value of 1 + 2 + 3 = 6.

Read More

Split and then add both sides of an array together in Java

The challenge You will receive an array as a parameter that contains 1 or more integers and a number n.

Read More

Sort Words by Position Index in Java

The challenge Your task is to sort a given string. Each word in the string will contain a single number.

Read More

How to get the Current Machine Name and Logged In User in Java

It’s very easy to get the current machine name and logged in user using Java.

Read More

How to install GraalVM on Mac

Install GraalVM with Homebrew Homebrew is the preferred way to install anything on your Mac.

Read More

How to Generate Random Integers with a Range in Java

Java comes with many different ways to generate random integers, even if you need to specify a lower and upper bound to constrain your required value for.

Read More

How to create ArrayList from Array in Java

The problem If you have a traditional array, that looks something like the following:

Read More

How to Remove all Vowels from a String in Java

The challenge Remove all vowels from the string. Vowels: a e i o u A E I O U The solution in Java code Option 1:

Read More

How to Solve Max-Min Arrays in Java

The challenge You are given an array of unique elements, and your task is to rearrange the values so that the first max value is followed by the first minimum, followed by second max value then second min value, etc.

Read More

How to do Basic Encryption in Java

The challenge The most basic encryption method is to map a char to another char by a certain math rule.

Read More

How to Find the Squares in Java

The challenge Complete the function that takes an odd integer (0 < n < 1000000) which is the difference between two consecutive perfect squares, and return these squares as a string in the format "bigger-smaller".

Read More

How to Get Longest Word in Sentence in Java

The challenge When given a string of space-separated words, return the word with the longest length.

Read More

Maximum Different of Int-Array in Java

The challenge You must implement a function that returns the difference between the biggest and the smallest value in a list(lst) received as a parameter.

Read More

Indexed Capitalization in Java

The challenge Given a string and an array of integers representing indices, capitalize all letters at the given indices.

Read More

How to Spacify a String in Java

The challenge Modify the spacify function so that it returns the given string with spaces inserted between each character.

Read More

How to Validate Usernames with Regex in Java

The challenge Write a simple regex to validate a username. Allowed characters are:

Read More

Sort Lexicographical Order of Substrings in Java

The challenge Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.

Read More

How to Perform Alphabetical Addition in Java

The challenge Your task is to add up letters to one letter.

Read More

How to Encrypt Words in Java

The challenge You want to create secret messages which must be deciphered.

Read More

How to Fold an Array in Java

The challenge In this challenge, you have to write a method that folds a given array of integers by the middle x-times.

Read More

Delete Occurrences of an Element if it occurs more than N times in Java

The challenge Given a list lst and a number N, create a new list that contains each number of lst at most N times without reordering.

Read More

How to Validate Phone Numbers in Java

The challenge Write a function that accepts a string, and returns true if it is in the form of a phone number.

Read More

How to Sort Array by Frequency in Java

The challenge Sort elements in an array by decreasing frequency of elements.

Read More

How to Calculate String Rotation in Java

The challenge Write a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string forward to match the second.

Read More

Compare Strings by Sum of Chars in Java

The challenge Compare two strings by comparing the sum of their values (ASCII character code).

Read More

How to Add Two Integers Without Arithmetic Operator in Java

The challenge Given two integers a, b, find The sum of them, BUT You are not allowed to use the operators + and –

Read More

Counting Method VarArgs in Java

The challenge Count how many arguments a method is called with.

Read More

How to Sum Consecutives in Java

The challenge You are given a list/array which contains only integers (positive and negative).

Read More

Replacing Occurences of Words in Java

The challenge You are given a string. You must replace any occurrence of the sequence coverage by covfefe, however, if you don’t find the word coverage in the string, you must add covfefe at the end of the string with a leading space.

Read More

Convert String to LeetSpeak in Java

The challenge Your task is to write a function toLeetSpeak that converts a regular english sentence to Leetspeak.

Read More

Credit Card Issuer Checking in Java

The challenge Given a credit card number we can determine who the issuer/vendor is with a few basic knowns.

Read More

Find Count of Most Frequent Item in an Array in Java

The challenge Complete the function to find the count of the most frequent item of an array.

Read More

Return Nth Smallest Element in Java

The challenge Given an array/list [] of integers, Find the Nth smallest element in this array of integers

Read More

Split String into Parts in Java

The challenge Split a given string into different strings of equal size.

Read More

Exes and Ohs in Java

The challenge Check to see if a string has the same amount of ‘x’s and ‘o’s.

Read More

How to make an arithmetic function in Java

The challenge Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them.

Read More

Using Apache POI to Get or Create a Sheet in Excel using Java

Apache POI provides a mechanism to work with Excel documents.

Read More

How to Resolve Scaling Squared Strings in Java

The challenge You are given a string of n lines, each substring being n characters long.

Read More

Determine the Last Digits of N^2 == N in Java

The challenge Let’s call an integer number N ‘green’ if N² ends with all of the digits of N.

Read More

How to Map over a List of Lists in Java

The challenge Write a function which maps a function over the lists in a list:

Read More

How to Differentiate a Polynomial in Java

The challenge Create a function that differentiates a polynomial for a given value of x.

Read More

Find the Sums of Perfect Squares in Java

The challenge The task is simply stated. Given an integer n (3 < n < 10<sup>9</sup>), find the length of the smallest list of perfect squares which add up to n.

Read More

[Solved] Error: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:repackage (repackage)

If you have come across this error when trying to build and deploy your Spring Boot Maven application then this post will help you!

Read More

How to Make a Spiral in Java

The challenge Your task, is to create a NxN spiral with a given size.

Read More

Find the Longest Common Subsequence in Java

The challenge from Wikipedia: The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequences in a set of sequences.

Read More

Find First and Last Position of Element in Sorted Array in Java

The challenge Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

Read More

Determine if Number is a Power of Three in Java

The challenge Given an integer n, return true if it is a power of three.

Read More

How to Count Binary Substrings in Java

The challenge Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are grouped consecutively.

Read More

Array Range between Integers in Java

The challenge Complete the function that takes two integers (a, b, where a < b) and return an array of all integers between the input parameters, including them.

Read More

Number of Rectangles in a Grid in Java

The challenge Given a grid of size m x n, calculate the total number of rectangles contained in this rectangle.

Read More

Longest vowel chain in Java

The challenge The vowel substrings in the word codewarriors are o,e,a,io.

Read More

Determine Unique String Characters in Java

The challenge In this challenge, you will be given two strings a and b and your task will be to return the characters that are not common in the two strings.

Read More

Difference of Volumes of Cuboids in Java

The challenge In this simple exercise, you will create a program that will take two lists of integers, a and b.

Read More

Sort by binary ones in Java

The challenge In this example you need to implement a function that sort a list of integers based on it’s binary representation.

Read More

Binomial Expansion in Java

The challenge Write a program that can do some algebra. Write a function expand that takes in an expression with a single, one character variable, and expands it.

Read More

Consecutive strings in Java

The challenge You are given an array(list) strarr of strings and an integer k.

Read More

Determine the Highest Scoring Word in Java

The challenge Given a string of words, you need to find the highest scoring word.

Read More

Solving Speed Control in Java

The challenge In John’s car the GPS records every s seconds the distance travelled from an origin (distances are measured in an arbitrary but consistent unit).

Read More

Calculate Miles per Gallon to Kilometers per Litre in Java

The challenge Create an application that will display the number of kilometers per liter (output) based on the number of miles per imperial gallon (input).

Read More

Find the Greatest Common Divisor in Java

The challenge Find the greatest common divisor of two positive integers.

Read More

How to Guess the Sequence in Java

The challenge You must guess a sequence and it has something to do with the number given.

Read More

Reversed sequence in Java

The challenge Build a function that returns an array of integers from n to 1 where n>0.

Read More

Count the Digit in Java

The challenge Take an integer n (n >= 0) and a digit d (0 <= d <= 9) as an integer.

Read More

Multiply all elements in an array in Java

The challenge Create a function multiplyAll/multiply_all which takes an array of integers as an argument.

Read More

Credit Card Mask in Java

The challenge Usually when you buy something, you’re asked whether your credit card number, phone number or answer to your most secret question is still correct.

Read More

How to Reverse a Number in Java

The challenge Given a number, write a function to output its reverse digits.

Read More

Positions Average in Java

The challenge Suppose you have 4 numbers: '0', '9', '6', '4' and 3 strings composed with them:

Read More

Determine the Date by the Day Number in Java

The challenge What date corresponds to the nth day of the year?

Read More

Correct the time-string in Java

The challenge You have to create a method, that corrects a given time string.

Read More

Shifter Words Challenge in Java

The challenge You probably know that some characters written on a piece of paper, after turning this sheet 180 degrees, can be read, although sometimes in a different way.

Read More

Find Maximum and Minimum Values of a List in Java

The challenge Make two functions, max and min that take a(n) array/vector of integers list as input and outputs, respectively, the largest and lowest number in that array/vector.

Read More

Valid Parentheses in Java

The challenge Write a function that takes a string of parentheses, and determines if the order of the parentheses is valid.

Read More

Boggle Word Checker in Java

The challenge Write a function that determines whether a string is a valid guess in a Boggle board, as per the rules of Boggle.

Read More

Reverse the bits in an integer in Java

The challenge Write a function that reverses the bits in an integer.

Read More

Spring Boot no main manifest attribute, in

You have created a ./target/.jar and have tried to run it using java -jar <app>.

Read More

Matrix Addition in Java

The challenge Write a function that accepts two square matrices (N x N two dimensional arrays), and return the sum of the two.

Read More

Numbers that are a power of their sum of digits in Java

The challenge The number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared).

Read More

Integer triangles in Java

The challenge You have to give the number of different integer triangles with one angle of 120 degrees which perimeters are under or equal a certain value.

Read More

Minimum path in squares in Java

The challenge You’re given a square consisting of random numbers, like so:

Read More

Pascal’s Diagonals in Java

The challenge Create a function that returns an array containing the first l digits from the nth diagonal of Pascal’s triangle.

Read More

Maximum Contiguous Sum in Java

The challenge Given an unsorted array of integer values, find the maximum positive sum of any contiguous range within the array.

Read More

Fibonacci Streaming in Java

The challenge You’re going to provide a needy programmer a utility method that generates an infinite sized, sequential IntStream which contains all the numbers in a fibonacci sequence.

Read More

Base-2 in Java

The challenge In this challenge you must convert integers numbers from and to a negative-base binary system.

Read More

Unique digits sequence in Java

The challenge Consider the following series: 0,1,2,3,4,5,6,7,8,9,10,22,11,20,13,24...There is nothing special between numbers `` and 10.

Read More

Palindrome integer composition in Java

The challenge The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2 = 595.

Read More

Count IP Addresses in Java

The challenge Implement a function that receives two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one).

Read More

Shortest Knight Path in Java

The challenge Given two different positions on a chess board, find the least number of moves it would take a knight to get from one to the other.

Read More

All Balanced Parentheses in Java

The challenge Write a function that makes a list of strings representing all of the ways you can balance n pairs of parentheses

Read More

Human readable duration format in Java

The challenge Your task in order to complete this challenge is to write a function which formats a duration, given as a number of seconds, in a human-friendly way.

Read More

Simple string expansion in Java

The challenge Consider the following expansion: // because "ab" repeats 3 times solve("3(ab)") == "ababab" // because "a3(b)" == "abbb", which repeats twice.

Read More

Hamming Numbers in Java

The challenge A Hamming number is a positive integer of the form 2i3j5k, for some non-negative integers i, j, and k.

Read More

Block sequence in Java

The challenge Consider the following array: [1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 12345678910, 1234567891011.

Read More

Roman Numerals Helper in Java

The challenge Create a RomanNumerals class that can convert a roman numeral to and from an integer value.

Read More

Closest pair of points in linearithmic time in Java

The challenge Given a number of points on a plane, your task is to find two points with the smallest distance between them in linearithmic O(n log n) time.

Read More

Find sum of top-left to bottom-right diagonals in Java

The challenge Given a square matrix (i.e. an array of subarrays), find the sum of values from the first value of the first array, the second value of the second array, the third value of the third array, and so on…

Read More

Sweeping trees in Java

The challenge You will be given a list of strings representing nodes in a rooted tree.

Read More

Detect Pangram in Java

The challenge A pangram is a sentence that contains every single letter of the alphabet at least once.

Read More

Remove the parentheses in Java

The challenge In this challenge you are given a string for example:

Read More

What century is it in Java

The challenge Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation.

Read More

Lost number in number sequence in Java

The challenge An ordered sequence of numbers from 1 to N is given.

Read More

Simple string reversal in Java

The challenge In this challenge, we are going to reverse a string while maintaining the spaces (if any) in their original place.

Read More

int32 to IPv4 in Java

The challenge Take the following IPv4 address: 128.32.10.1 This address has 4 octets where each octet is a single byte (or 8 bits).

Read More

Perimeter of squares in a rectangle in Java

The challenge The drawing shows 6 squares the sides of which have a length of 1, 1, 2, 3, 5, 8.

Read More

Palindrome chain length in Java

The challenge Number is a palindrome if it is equal to the number with digits in reversed order.

Read More

String array duplicates in Java

The challenge You are given an array of strings and your task is to remove all consecutive duplicate letters from each string in the array.

Read More

Even or Odd Array Sum in Java

The challenge Given a list of numbers, determine whether the sum of its elements is odd or even.

Read More

String Permutations in Java

The challenge In this challenge, you have to create all permutations of an input string and remove duplicates if present.

Read More

Remove a Specific Element of an Array in Java

The challenge You will be given a certain array of length n, such that n > 4, having positive and negative integers but there will be no zeroes and all the elements will occur once in it.

Read More

Upside down numbers in Java

The challenge Consider the numbers 6969 and 9116. When you rotate them 180 degrees (upside down), these numbers remain the same.

Read More

Rotate matrix counter-clockwise N times in Java

The challenge In this challenge your mission is to rotate matrix counter-clockwise N times.

Read More

Square Matrix Multiplication in Java

The challenge Write a function that accepts two square (NxN) matrices (two dimensional arrays), and returns the product of the two.

Read More

Count the divisible numbers in Java

The challenge Complete the function that takes 3 numbers x, y and k (where x ≤ y), and returns the number of integers within the range [x.

Read More

Averages of numbers in Java

The challenge Get the averages of these numbers Write a method, that gets an array of integer-numbers and return an array of the averages of each integer-number and his follower, if there is one.

Read More

Decimal to Factorial and Back in Java

The challenge Coding decimal numbers with factorials is a way of writing out numbers in a base system that depends on factorials, rather than powers of numbers.

Read More

Vowel Count in Java

The challenge Return the number (count) of vowels in the given string.

Read More

Equal Sides Of An Array in Java

The challenge You are going to be given an array of integers.

Read More

Largest 5 digit number in a series in Java

The challenge In the following 6 digit number: 283910 91 is the greatest sequence of 2 consecutive digits.

Read More

Next smaller number with the same digits in Java

The challenge Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits.

Read More

Count of positives / sum of negatives in Java

The challenge Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.

Read More

Find the stray number in Java

The challenge You are given an odd-length array of integers, in which all of them are the same, except for one single number.

Read More

4 By 4 Skyscrapers in Java

The challenge In a grid of 4 by 4 squares you want to place a skyscraper in each square with only some clues:

Read More

How to Fix: package org.junit.jupiter.api does not exist

The problem If you have received the package org.junit.jupiter.api deos not exist error when trying to run a JUnit Java Test with Maven, it’s because of a missing dependency in your pom.

Read More

Sum by Factors in Java

The challenge Given an array of positive or negative integers

Read More

Count the divisors of a number in Java

The challenge Count the number of divisors of a positive integer n.

Read More

My smallest code interpreter in Java

The challenge Inspired from real-world Brainf**k, we want to create an interpreter of that language which will support the following instructions:

Read More

Pick peaks in Java

The challenge Write a function that returns the positions and the values of the “peaks” (or local maxima) of a numeric array.

Read More

Number of trailing zeros of N in Java

The challenge Write a program that will calculate the number of trailing zeros in a factorial of a given number.

Read More

Alphabetic Anagrams in Java

The challenge Consider a “word” as any sequence of capital letters A-Z (not limited to just “dictionary words”).

Read More

Remove file from Git without deleting locally

If you find yourself in a position where you have already committed some files to git, and they are in the remote repository already, but you want to remove them from you repository without deleting them locally, you can do the following:

Read More

Recover a secret string from random triplets in Java

The challenge There is a secret string which is unknown to you.

Read More

Range Extraction in Java

The challenge A format for expressing an ordered list of integers is to use a comma separated list of either

Read More

Reversed Words in Java

The challenge Complete the solution so that it reverses all of the words within the string passed in.

Read More

CamelCase Method in Java

The challenge Write a simple CamelCase method for strings. All words must have their first letter capitalized without spaces.

Read More

Even or Odd in Java

The challenge Create a function that takes an integer as an argument and returns “Even” for even numbers or “Odd” for odd numbers.

Read More

Square Every Digit in Java

The challenge You need to square every digit of a number and concatenate them.

Read More

Simple number sequence in Java

The challenge You are given a string of numbers in sequence and your task will be to return the missing number.

Read More

Roman Numerals Encoder in Java

The challenge Create a function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer.

Read More

First Variation on Caesar Cipher in Java

The challenge The action of a Caesar cipher is to replace each plaintext letter (plaintext letters are from ‘a’ to ‘z’ or from ‘A’ to ‘Z’) with a different one a fixed number of places up or down the alphabet.

Read More

Century From Year in Java

The challenge The first century spans from the year 1 up to and including the year 100, The second – from the year 101 up to and including the year 200, etc.

Read More

Find the Smallest Number in Java

The challenge You have a positive number n consisting of digits.

Read More

Convert Array to Tree in Java

The challenge You are given a non-null array of integers. Implement the method arrayToTree which creates a binary tree from its values in accordance to their order, while creating nodes by depth from left to right.

Read More

Common Denominators in Java

The challenge You will have a list of rationals in the form

Read More

Primes in Numbers in Java

The challenge Given a positive number n > 1 find the prime factor decomposition of n.

Read More

Maximum subarray sum in Java

The challenge The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:

Read More

Validate Credit Card Number in Java

The challenge Let’s implement the Luhn Algorithm, which is used to help validate credit card numbers.

Read More

Find the unique number using Java

The challenge There is an array with some numbers. All numbers are equal except for one.

Read More

Find The Parity Outlier in Java

The challenge You are given an array (which will have a length of at least 3, but could be very large) containing integers.

Read More

Find the missing letter using Java

The challenge Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.

Read More

Determine the order of braces is valid using Java

The challenge Write a function that takes a string of braces, and determines if the order of the braces is valid.

Read More

[Solved] PKIX path building failed: unable to find valid certification path to requested target

The problem It may happen to you that when you try and pull some Java dependencies, you will get the annoying PKIX path building failed: sun.

Read More

How to Find the odd int in Java

The challenge Given an array of integers, find the one that appears an odd number of times.

Read More

Count the number of Duplicates in Java

The challenge Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string.

Read More

Calculating Simple Max Digit Sum in Java

The challenge In this challenge, you will be given an integer n and your task will be to return the largest integer that is <= n and has the highest digit sum.

Read More

The String Combat Challenge in Java

The challenge After a long conflict, the rulers of Nek and Glo have decided that a final duel should decide the fate of their countries.

Read More

Solving Single Word Pig Latin in Java

The challenge Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.

Read More

Count the Days in Java

The challenge Little Annie is very excited for upcoming events. She want’s to know how many days she have to wait for a specific event.

Read More

Java HashMap Create or Increment Value

If you are using a HashMap to keep a running total of a series of elements, then you often need to increment a HashMap item, but if it doesn’t exist in the map yet, then you need to rather create it.

Read More

Get the Strongest even number in an interval in Java

The challenge A strongness of an even number is the number of times we can successively divide by 2 until we reach an odd number starting with an even number n.

Read More

What time is it? in Java

The challenge How many times have we been asked this simple question in our daily lives by family, friends and strangers alike?

Read More

Building a String Pyramid in Java

The challenge You have to build a pyramid. This pyramid should be built from characters from a given string.

Read More

Cartesian coordinates from degree angle in Java

The challenge Write a simple function that takes polar coordinates (an angle in degrees and a radius) and returns the equivalent cartesian coordinates (rounded to 10 places).

Read More

Sort array by sorting its smallest sub-array in Java

The challenge Given an array of integers, arr, find out 2 indices m, n(0<=m<=arr.

Read More

Excessively Abundant Numbers in Java

The challenge An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself.

Read More

Unique Substring From Joined Strings in Java

The challenge Write a function that takes two strings, A and B, and returns the length of the longest possible substring that can be formed from the concatenation of either A + B or B + A containing only characters that do not appear in both A and B.

Read More

Converting from Base 10 to 16 (Decimal to Hex) in Java

The challenge Convert an integer which is base 10, to a hexadecimal base 16 string.

Read More

String polynomial converter in Java

The challenge Your task is to programe: String convertToString(int[] pol) {.

Read More

How to Remove all Exclamation Marks from a String in Java

The challenge Write function RemoveExclamationMarks which removes all exclamation marks from a given string.

Read More

How to Convert a Number to a String in Java

The challenge We need a function that can transform a number into a string.

Read More

How to Remove Spaces in a String in Java

The challenge Simple, remove the spaces from the string, then return the resultant string.

Read More

How many stairs will Suzuki climb in 20 years? in Java

The challenge Suzuki is a monk who climbs a large staircase to the monastery as part of a ritual.

Read More

Determine if N is divisible by X and Y in Java

The challenge Create a function that checks if a number n is divisible by two numbers x AND y.

Read More

How to Sum a Mixed Array in Java

The challenge Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers.

Read More

Calculate the Volume of a Cuboid in Java

A Cuboid is a geometric object that is more or less cubic in shape.

Read More

Find the first non-consecutive number in Java

The challenge Your task is to find the first element of an array that is not consecutive.

Read More

Alternating String Casing in Java

The challenge altERnaTIng cAsE <=> ALTerNAtiNG CaSe Define String.prototype.toAlternatingCase (or a similar function/method such as to_alternating_case/toAlternatingCase/ToAlternatingCase in your selected language; see the initial solution for details) such that each lowercase letter becomes uppercase and each uppercase letter becomes lowercase.

Read More

Solving the Pythagorean Triple in Java

The challenge Given an array of 3 integers a, b and c, determine if they form a pythagorean triple.

Read More

How to Correct the Mistakes of the Character Recognition Software in Java

The challenge Character recognition software is widely used to digitise printed texts.

Read More

Solving “Duck Duck Goose” in Java

The challenge The objective of Duck, duck, goose is to walk in a circle, tapping on each player’s head until one is chosen.

Read More

Calculate averages from an int array in Java

The challenge Write function avg which calculates average of numbers in given list.

Read More

How to Rotate a String in Java

Rotating a String in Java is a common interview question, and albeit it quite a simple one, it tests many fundamental concepts.

Read More

Calculate the Sum without highest and lowest number in Java

The challenge Sum all the numbers of the array except the highest and the lowest element (the value, not the index!

Read More

How to Convert a String to an Array in Java

Java makes it easy to convert a string to an array by providing the built-in .

Read More

How to Loop and Combine Three Strings in Java

The challenge Create a function that will return a string that combines all of the letters of the three inputed strings in groups.

Read More

How to Localize The Barycenter of a Triangle in Java

The challenge The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides.

Read More

How to Calculate a Valid Square in Java

The challenge Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.

Read More

How to Calculate Age Range Compatibility as an Equation in Java

The challenge Everybody knows the classic “half your age plus seven” dating rule that a lot of people follow (including myself).

Read More

How to Find the Longest Mountain in Array in Java

The challenge Let’s call any (contiguous) subarray B (of A) a mountain if the following properties hold:

Read More

How to Solve the “Decode a String” Challenge in Java

The challenge Given an encoded string, return its decoded string.

Read More

How to Find the Maximum Difference Between Node and Ancestor in Java

The challenge Given the root of a binary tree, find the maximum value V for which there exist different nodes A and B where V = |A.

Read More

How to Find the Integral using Java

The challenge Create a function that finds the integral of the expression passed.

Read More

How to Build Strings from a Size in Java

The challenge Write a function stringy that takes a size and returns a string of alternating '1s' and '0s'.

Read More

Best Time to Buy and Sell Stock in Java

The challenge Say you have an array for which the ith element is the price of a given stock on day i.

Read More

How to Solve the “To square(root) or not to square(root)” Challenge in Java

The challenge Write a method, that will get an integer array as parameter and will process every number from this array.

Read More

Solving the Rule of Divisibility by 13 in Java

The challenge "A divisibility rule is a shorthand way of determining whether a given integer is divisible by a fixed divisor without performing the division, usually by examining its digits.

Read More

How to Calculate Buddy Strings in Java

The challenge Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false.

Read More

How to Flip a Binary Matrix in Java

The challenge Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.

Read More

How to Tilt a Binary Tree in Java

The challenge Given the root of a binary tree, return the sum of every tree node’s tilt.

Read More

How to solve the House Robber Challenge in Java

The challenge You are a professional robber planning to rob houses along a street.

Read More

How to Solve the Bag of Tokens Challenge in Java

The challenge You have an initial power of P, an initial score of ``, and a bag of tokens where tokens[i] is the value of the i<sup>th</sup> token (0-indexed).

Read More

How to Find the Smallest Divisor Given a Threshold in Java

The challenge Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division.

Read More

How to Sort and Star a String Array in Java

The challenge You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and then return the first value.

Read More

How to Count Consecutive Characters in Java

The challenge Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.

Read More

How to Abbreviate a Two Word Name in Java

The challenge Write a function to convert a name into initials.

Read More

How to Sort a Linked List using Insertion Sort in Java

The challenge Sort a linked list using insertion sort. A graphical example of insertion sort.

Read More

How to Remove First and Last Character in a String in Java

The challenge The goal is to create a function that removes the first and last characters of a string.

Read More

How to Distribute Halloween Candies by Rating Value in Java

The challenge There are N children standing in a line. Each child is assigned a rating value.

Read More

How to Distribute Halloween Candies in Java

The challenge You have n candies, the i<sup>th</sup> candy is of type candies[i].

Read More

How to Solve the Maximize Distance to Closest Person Challenge in Java

The challenge You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the i<sup>th</sup> seat, and seats[i] = 0 represents that the i<sup>th</sup> seat is empty (0-indexed).

Read More

How to Get Character from ASCII Value in Java

The challenge Write a function which takes a number and returns the corresponding ASCII char for that value.

Read More

Finding a Needle in a Haystack in Java

The challenge Can you find the needle in the haystack?

Read More

How to Solve the Champagne Tower in Java

The challenge We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.

Read More

How to Solve the 132 Pattern in Java

The challenge Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].

Read More

How to Replace all Vowels in a String in Java

The challenge Replace all vowel to exclamation mark in the sentence.

Read More

How to Get the N-th Power in Java

The challenge You are given an array with positive numbers and a number N.

Read More

How to Count the Minimum Depth of a Binary Tree in Java

The challenge Given a binary tree, find its minimum depth.

Read More

How to Solve the House Robber II Challenge in Java

The challenge You are a professional robber planning to rob houses along a street.

Read More

How to Clone a Graph in Java

The challenge Given a reference of a node in a connected undirected graph.

Read More

How to Return Random Values in Java

The challenge Ghost objects are instantiated without any arguments. Ghost objects are given a random color attribute of white" or “yellow” or “purple” or “red” when instantiated

Read More

How to Compare Version Numbers in Java

The challenge Compare two version numbers version1 and version2. If <em>version1</em>&nbsp;>&nbsp;<em>version2</em> return 1; if <em>version1</em>&nbsp;<&nbsp;<em>version2</em> return -1;otherwise return ``.

Read More

How to Return the First N Elements in Java

The challenge Create a method take that accepts a list/array and a number n, and returns a list/array array of the first n elements from the list/array.

Read More

How to Search a 2d Matrix/Array in Java

The challenge Write an efficient algorithm that searches for a value in an m x n matrix.

Read More

Calculate the Surface Area and Volume of a Box with Java

The challenge Write a function that returns the total surface area and volume of a box as an array: [area, volume]

Read More

Find Numbers which are Divisible by given Number in Java

The challenge Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor.

Read More

Get the Maximum XOR of Two Numbers in an Array in Java

The challenge Given a non-empty array of numbers, a, a1, a2, … , an-1, where 0 ≤ ai < 231.

Read More

How to Get the Opposite of a Number in Java

The challenge Given a number, find its opposite. Examples: 1: -1 14: -14 -34: 34 The solution in Java We return the number itself multiplied by a negative 1.

Read More

How to Find the Area or Perimeter of a 4-sided Polygon using Java

The challenge You are given the length and width of a 4-sided polygon.

Read More

How to Parse Int from Char in Java

The challenge We take in a String where the first place contains a number, write a function that takes in this String and returns an int containing it.

Read More

How to Search a Binary Tree in Java

The challenge Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums.

Read More

How to Rotate a Singly Linked List in Java

The challenge Given a linked list, rotate the list to the right by k places, where k is non-negative.

Read More

How to Insert into a Binary Search Tree using Java

The challenge You are given the root node of a binary search tree (BST) and a value to insert into the tree.

Read More

Find the Complement of Base 10 Integer in Java

The challenge Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on.

Read More

Solve the Number of Recent Calls Challenge in Java

The challenge You have a RecentCounter class which counts the number of recent requests within a certain time frame.

Read More

How to Calculate the Summation of a Number in Java

The challenge Write a program that finds the summation of every number from 1 to num.

Read More

How to Calculate all Unique Combinations of a Target using Backtracking in Java

The challenge Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.

Read More

Calculate the Total Amount of Points using Java

The challenge Our football team finished the championship. The result of each match look like “x:y”.

Read More

Calculate the biggest of 3 numbers using Java

The challenge Task Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, () In other words , try every combination of a,b,c with [*+()] , and return the Maximum Obtained Consider an Example : With the numbers are 1, 2 and 3 , here are some ways of placing signs and brackets:

Read More

How to Count an Array of Boolean Values in Java

The challenge Consider an array/list of sheep where some sheep may be missing from their place.

Read More

How to Solve the Car Pooling Challenge in Java

The challenge You are driving a vehicle that has capacity empty seats initially available for passengers.

Read More

How to Repeat a String in Java

The challenge Write a function called repeat_str which repeats the given string src exactly count times.

Read More

How to Find the Smallest Integer in the Array in Java

The challenge Given an array of integers your solution should find the smallest integer.

Read More

How to Count Odd Numbers Below N using Java

The challenge Given a number n, return the number of positive odd numbers below n, EASY!

Read More

How to get the Length of the Last Word in a String using Java

The challenge Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

Read More

How to Convert a Number to Reversed Array of Digits in Java

The challenge Given a random non-negative number, you have to return the digits of this number within an array in reverse order.

Read More

How to Solve Unique Paths III in Java

The challenge On a 2-dimensional grid, there are 4 types of squares:

Read More

How to Find the Mean/Average of a List of Numbers in Java

The challenge Find the mean (average) of a list of numbers in an array.

Read More

How to Calculate BMI in Java

The challenge BMI stands for Body Mass Index and is a value derived from the mass and height of a person.

Read More

How to Solve the Robot Bounded In Circle Challenge in Java

The challenge On an infinite plane, a robot initially stands at (0, 0) and faces north.

Read More

How to Convert a String to a Number in Java

The challenge We need a function that can transform a string into a number.

Read More

How to Convert an Integer to Binary using Java

The challenge Given a non-negative integer n, write a function toBinary/ToBinary which returns that number in a binary format.

Read More

How to create a Logical Operator in Java

Exclusive “or” (xor) Logical Operator In some scripting languages like PHP, there exists a logical operator (e.

Read More

How to merge sorted integer arrays (without duplicates) in Java

The challenge Write a function that merges two sorted arrays into a single one.

Read More

Find the Force of Gravity Between Two Objects with Java

The challenge Your job is to find the gravitational force between two spherical objects (obj1 , obj2).

Read More

Playing the Bulls and Cows Game in Java

The challenge You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is.

Read More

Calculate the Sum of Root To Leaf Binary Numbers in Java

The challenge Given a binary tree, each node has value `` or 1.

Read More

How to “Rock Paper Scissors” in Java

The challenge Let’s play Rock Paper Scissors! You have to return which player won!

Read More

Get the mean of an array in Java

The challenge It’s the academic year’s end, fateful moment of your school report.

Read More

How to Convert Hex to Decimal in Java

The challenge Write a function that converts an input string contains a hex value, and return a decimal.

Read More

Character with Longest Consecutive Repetition in Java

The challenge For a given string s find the character c (or C) with longest consecutive repetition and return:

Read More

Cryptanalysis Word Patterns in Java

The challenge In cryptanalysis, words patterns can be a useful tool in cracking simple ciphers.

Read More

Backspaces in String Challenge using Java

The challenge Assume "#" is like a backspace in string. This means that string "a#bc#d" actually is "bd"

Read More

The SongDecoder Dubstep Challenge with Java

The challenge Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance.

Read More

Break camelCase Challenge in Java

The challenge Complete the solution so that the function will break up camel casing, using a space between words.

Read More

The “Split Strings” Challenge using Java

The challenge Complete the solution so that it splits the string into pairs of two characters.

Read More

Solving the “Double Cola” Challenge using Java

The challenge Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a “Double Cola” drink vending machine; there are no other people in the queue.

Read More

Convert Seconds to Human Readable Time (HH:MM:SS) using Java

The challenge Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS)

Read More

Solving the “Mexican Wave” Challenge using Java

The challenge Task Your task is to create a function that turns a string into a Mexican Wave.

Read More

Convert String to Camel Case using Java

The challenge Complete the method/function so that it converts dash/underscore delimited words into camel casing.

Read More

Sort a Java Integer in Descending Order

The challenge Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order.

Read More

Get the Sum of Digits / Digital Root using Java

The challenge Digital root is the recursive sum of all the digits in a number.

Read More

Check if Valid Sudoku Blocks in Java

The challenge of solving valid Sudoku blocks Determine if a 9×9 Sudoku board is valid.

Read More

FizzBuzz in Java

The challenge Write a program that outputs the string representation of numbers from 1 to n.

Read More

Python Splices reimplemented in Java

Python has a fantastic feature called slices. It allows you to work with a list, set or string by it’s index items.

Read More

Is a Valid Palindrome with Java

The challenge Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Read More

Is a Valid Anagram with Java

The challenge Given two strings s and t , write a function to determine if t is an anagram of s.

Read More

How to ReImplement strStr() in Java

What we want to achieve Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Read More

Third Maximum Number with Java

The challenge Given a non-empty array of integers, return the third maximum number in this array.

Read More

First Unique Character in a String using Java

The challenge Given a string, find the first non-repeating character in it and return its index.

Read More

How to fix the Release Version 5 Not Supported error in IntelliJ

What do you do when you create a new Maven Java project, and when you run it, you get the following error:

Read More

How to Reverse an Integer in Java

The challenge Given a 32-bit signed integer, reverse digits of an integer.

Read More

Reverse a String in-place using Java

The challenge Write a function that reverses a string. The input string is given as an array of characters char[].

Read More

Check if a Java array Contains Duplicates

The challenge Given an array of integers, find if the array contains any duplicates.

Read More

The Array Height Checker Problem in Java

The challenge Students are asked to stand in non-decreasing order of heights for an annual photo.

Read More

Find the Squares of a Sorted Array in Java

The challenge Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.

Read More

Sorting a Java Array by Parity

The challenge Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.

Read More

Remove Duplicates from Sorted Array in Java

Say you have an array of primitive integers and you want to remove all duplicates.

Read More

Replace Elements with Greatest Element on Right Side using Java

The challenge Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

Read More

The Valid Mountain Array Problem using Java

Introducing the problem Given an array A of integers, return true if and only if it is a valid mountain array.

Read More

Find Numbers with Even Number of Digits using Java

The challenge Given an array nums of integers, return how many of them contain an even number of digits.

Read More

How to use a Java HashSet by example

What is a HashSet A HashSet is an unordered collection containing unique elements.

Read More

The Decoded String at Index using Java

The Challenge An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:

Read More

Find the Minimum Absolute Difference in BST using Java

The question Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.

Read More

Find Maximum Subarrays using Java

The problem Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Read More

Finding Number Complements using Java

The problem Given a positive integer num, output its complement number.

Read More

Comparing Java and Javascript

Perhaps the first thing that most people ask when they hear the names of these two programming languages are.

Read More

The Primary Data Types in Java

In Java there are eight basic data types; which are: byte, short, int, long, float, double, boolean and char.

Read More

Comparing Objects in Java

TLDR; When to use == in Java When comparing two operands.

Read More

Overloading Operators in Java

As with many programming languages such as C, C++ and C# (known commonly as the C family), it is possible to “overload methods” (sometimes called functions if not used in classes, such as C) in order to take a different amount of parameters so that they can be used in multiple scenarios with similar internals.

Read More

How to get the Range Sum of Binary Search Tree using Java

Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).

Read More

Mocha Java Decompiler Download

Mocha is a Java Decompiler and is 100% FREE to use.

Read More