Length of the Longest Consecutive Zeroes in Binary Representation of a Number in Java

Ashin Vincent
Updated on 27-Feb-2025 12:55:23

214 Views

You are given a number (N); you need to find the length of the longest consecutive zeroes in the binary representation of the number using different approaches. Example Input N = 529 The binary form of 529 is 1000010001. Output The longest chain of zeroes in the binary form is 0000 with a length of 4. Hence, the answer is 4. Approach 1: Using Division and Modulus In this approach we use division and modulus operations to convert decimal to binary and then count the maximum zeroes in the binary number. Steps for implementation The following steps explain ... Read More

Lead Number in Java

Ashin Vincent
Updated on 27-Feb-2025 12:43:07

868 Views

A lead number is a number whose sum of even digits is equal to the sum of odd digits. In this article, we will learn about lead numbers and programs to check if a number is a lead number or not. Lead number example Let’s take the number 615341. The sum of even digits is 6 + 4 = 10. The sum of odd digits is 1 + 5 + 3 + 1 = 10. Here, the sum of even digits = the sum of odd digits, so 615341 is a lead number Arithmetic Approach This approach extracts digits ... Read More

Implement Associative Array in Java

Ashin Vincent
Updated on 27-Feb-2025 12:28:06

214 Views

What is an associative array? An associative array stores data in key-value pairs where we can retrieve values using unique keys. There is a significant difference between standard arrays and associative arrays. Normal arrays use numbers for indexing (like arr[0], arr[1], arr[2]). Whereas in an associative array, we use meaningful names such as "name" or "city” to identify each value. Example Let's consider a list of student grades where names act as keys − Key (Student Name): Value (Marks) Raju: 85 Krishna: 90 Yash: 78 This lets us find the grades of students by using their names instead of ... Read More

Print Odd Elements at Odd Index in Java

Ashin Vincent
Updated on 27-Feb-2025 12:17:42

184 Views

In this article, we will learn how to find and print the odd numbers that are present at odd index positions in an array. First we will understand the problem with the help of an example, and then we will learn three approaches to implement it in Java. Example Consider the array = [2, 1, 4, 4, 5, 7]. The odd numbers at odd indices are 1 and 7. Explanation The indexing of an array starts from 0. Here the element 1, which is an odd number, is present at index 1, which is an odd index. In the same ... Read More

Generate Random Hexadecimal Value in Java

Ashin Vincent
Updated on 27-Feb-2025 12:03:49

202 Views

In this article, we will learn how to generate random hexadecimal number values in Java. Random hexadecimal values are used in many applications, like unique identifiers, cryptographic keys, session tokens, or colour codes. We will discuss three different ways to generate random hexadecimal values in Java − Using Random – A simple, fast method to make random hexadecimal values. Using SecureRandom – Best for secure random hexadecimal numbers. Using BigInteger – Helps produce large random hexadecimal numbers. 1. Using Random In this approach, we use the Random class to produce random numbers from 0 to 15. After ... Read More

James Gosling: The Father of Java

Ashin Vincent
Updated on 27-Feb-2025 11:47:13

602 Views

James Arthur Gosling, also known as the Father of Java, is one of the greatest minds in computer science and programming history. He created the Java programming language in 1994, which became a revolutionary invention that transformed the software development industry. Java lets developers run a single code on any device, which makes it a platform-independent language. Other than java, Gosling has worked on several technical areas such as Artificial intelligence, software engineering and cloud computing. Early life and education James Gosling was born on May 19, 1955, in Calgary, Alberta, Canada. He developed an interest in computers at an ... Read More

Increment All Elements of an Array by One in Java

Ashin Vincent
Updated on 27-Feb-2025 11:38:50

111 Views

Arrays are one of the most fundamental data structures in programming, and they are used to store elements of the same data type in contiguous memory locations. If you are not familiar with the array concept, do check out this article on Arrays. In this article, we will learn how to increment every element of an array by one and print the incremented array. For example, If the input array is [3, 7, 10] The output should be [4, 8, 11] We can solve this problem using different approaches − Using for-loop Using java streams Using arrays.setAll() ... Read More

Find Hyperfactorial in Java

Ashin Vincent
Updated on 27-Feb-2025 11:18:17

147 Views

What is hyperfactorial? The hyperfactorial of a number is the product of numbers from 1 to the given number where each number is raised to the power of itself. For example, the hyperfactorial of 4 will be − = 1^1 * 2^2 * 3^3 * 4^4 = 1*4*27*256 = 27648 So we can say that the formula for finding hyperfactorial is − H(n)=1^1 * 2^2 *3^3 * 4^4 * 5^5 * . . . . . . . . . * n^n In this article, we will learn different approaches to find the hyperfactorial of a number, ... Read More

Pad a String in Java

Ashin Vincent
Updated on 27-Feb-2025 10:55:09

335 Views

What is string padding? String padding means adding extra spaces or characters to the string to reach a specified length. This extra character or space can be added before the string, after the string, or on both sides of the string. This is useful for formatting output or aligning text in documents in order to improve the overall appearance of the content. For example, while displaying a table, padding helps to align the content properly so that every column in the lineup is correct. Approaches to pad a string in Java There are multiple approaches to pad a string in ... Read More

Python Program to Find Area of Square

AYUSH MISHRA
Updated on 27-Feb-2025 09:13:43

0 Views

Problem DescriptionA square is a closed two-dimensional figure having 4 equal sides. Each angle of a square is 90 degrees. The area of a square is the space enclosed within its four sides. In this problem, we are given the side of a square, and we have to find the area of the square. In this tutorial, we are going to find the area of a given square in Python using different approaches.Example 1Input:side = 6 unitsOutput:36 square unitsExplanationUsing the formula to calculate the area of the square: side × side = 6 × 6 = 36 square unitsExample 2Input:side ... Read More

Advertisements