Minimum moves to segregate even followed by odd elements in Array

Introduction This tutorial will find out minimum moves to segregate even followed by odd elements in an Array using Java programming language. The function will put all even numbers first, and then odd numbers and finally count the number of moves required to arrange all elements in the desired order. This example also works on duplicate elements but does not…

Return array of products of all other numbers from a given array

Introduction This tutorial will show you how to return array of products of all other numbers from a given array. Let’s say you are given an array of non-zero integers. So you have to return an output array of products of all other numbers except the number itself.

Move Non-Zero Array Elements to Left using Java

Introduction This examples shows how to move all non-zero elements (if any) in an array to the left and all zero elements to the right of the array using Java. Your integer array may hold zero (0) and non-zero (1, 2, 4, etc.) elements. You have a requirement to have all non-zero elements first followed by 0 elements in the…

Java Anonymous Class

A class that has no name is known as anonymous class. Java Anonymous class can be created in two ways: Class Interface For more information please read https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html#accessing Anonymous classes enable you to make your code more concise. They enable you to declare and instantiate a class at the same time. They are like local classes except that they do…

String Reverse Example In Java

String Reverse This tutorial will show you string reverse example in Java. You can use various ways to reverse a string in Java and I have presented here five ways to reverse a string. String class in Java is an immutable class and that’s why it does not have reverse() method to reverse the given string. I will use here…