Found 33676 Articles for Programming

Java Program to Segregate 0s on Left Side & 1s on Right Side of the Array

Rudradev Das
Updated on 06-Aug-2024 22:37:14

2K+ Views

Segregation is a process in the field of software engineering where a code is forced to depend on those methods that are not in use. The segregation interface is known as ISP. It splits the interfaces that are vast in nature. In a Java environment, there are lots of advantages to implementing the segregation principle. It increases the readability of the particular code. It also helps to maintain that particular code conveniently. Problem Statement There is an array of 7s and 16s aimlessly. We must segregate the 7s on the left side and the 16s on the right. The basic ... Read More

Java Program to Search User Defined Object From a List By using Binary Search Comparator

Rudradev Das
Updated on 11-Apr-2023 15:49:36

335 Views

Java comparator interface used to sort Java objects. A comparator class in Java compares the different objects (Obj 01, Obj 02) by invoking the "java. util. comparator". In this method the objects can be compared on the basis of the return value. It can be positive, equal or negative in comparison. The process provides user multiple sorting sequences. There are lots of method by which we can perform the comparison between two methods. public int compare class (obj 1, obj 2) - Perform comparison between two objects. public Boolean equals (obj) - Compare current object with specified object. ... Read More

Code Solution to sword puzzle

Vaishnavi Tripathi
Updated on 09-Feb-2024 16:22:38

460 Views

We will discuss two approaches to solve the sword puzzle. In the first approach, we will use circular linked list, while the second approach is based on general intuition. In this article, we will discuss what is a sword puzzle problem and how we can solve a sword puzzle problem. Problem Statement We have an arrangement of n people in a circle in which, first person is carrying a sword. The first person kills the second person and hands over the sword to the next alive person in the circle. Now the next person carrying the sword kills the next ... Read More

Java Program to Represent Linear Equations in Matrix Form

Rudradev Das
Updated on 23-Nov-2024 03:44:51

592 Views

In this segment of Java programming, we are going to learn and discover certain programs by which we can represent linear equations in Matrix form. To do these programs, we first have to learn about linear equations and Matrix forms, their types, and how they are solved by simple mathematical methods. We will learn how to integrate a scanner class of java.util package to take input from the user using Java build code. The array will initialize to store some variables as input for the problem matrix. Then, it will be converted into a loop by which the problem equation will ... Read More

Java Program to Illustrate a Method without Parameters but with Return Type

Sakshi Ghosh
Updated on 26-Dec-2024 20:46:37

5K+ Views

In Java, a method is a block of code that performs a specific task. Methods can take zero or more parameters and can also return a value. When a method returns a value, we call it a method with a return type. A method without parameters but with a return type is a method that does not take any parameters but returns a value. This type of method is useful when we need to perform a specific task that does not require any input parameters, but we need to get a result from that task. First, let us get acquainted ... Read More

Java Program to Illustrate a Method without Parameters and Return Type

Sakshi Ghosh
Updated on 11-Apr-2023 14:55:22

465 Views

First, let us get acquainted with the syntax, and examples, and then finally the implementation. The methods in Java are of great importance since it allows reusability of the same code, reducing the number of statements to be written within the code. There are three main parts of the method in order to make it executable. Declaration of the method. Definition of the method. Invoking the method. Method invoking is the last step, while the other two can be interchanged. The only thing to be kept in mind here is, the method must be declared before invoking it. ... Read More

Java Program to Illustrate a Method with 2 Parameters and without Return Type

Sakshi Ghosh
Updated on 11-Apr-2023 14:54:10

2K+ Views

A method without a return type is termed a void method since it returns nothing. This method can accept multiple parameters. In this tutorial, we will implement Java programs illustrating a method with two parameters and without return type. First of all, we are going to get acquainted with the syntax, examples, and, finally implementation. Syntax public static void method_name (int parameter1, int parameter2) Here, public − It is the access specifier specifying who can access this method. static − It is mandatory to make the method static to avoid errors. void − it denotes that this method returns ... Read More

Java program to handle Unchecked Exception

Sakshi Ghosh
Updated on 24-Sep-2024 21:43:45

1K+ Views

In this article, we will learn to handle Unchecked Exception in Java. Exceptions are the unexpected circumstances occurring during the implementation of the program i.e., at the run time, that interrupt the usual working of the program. It can occur due to various reasons such as Illegal input given by the user, Failure of the devices, Loss of network connection, Physical limitations, Code faults, trying to open an unavailable file, etc. There are two major categories of Exceptions  − Checked Exception ... Read More

Java Program to Handle Divide by Zero and Multiple Exceptions

Shiva Keerthi
Updated on 31-May-2024 14:07:14

10K+ Views

Exceptions are the unusual events which disrupt the normal flow of execution of a program. When an exception occurs an object called exception object is generated, which contains details of exception like name, description, state of program. In this section, we are going to write a java program to handle divide by zero exception and how to handle multiple exceptions. Types of Exceptions− There are three types of exceptions − Checked exception − Checked exceptions are compile time exceptions i.e, they are checked during compilation of program.These cannot be ignored and must be handled by the programmer. ... Read More

Java Program to Find Sum of First N Odd numbers and Even numbers

Shiva Keerthi
Updated on 11-Apr-2023 14:17:21

4K+ Views

In this article, we are going to write a java program to find the sum of first n Odd and Even numbers. A number can be divided into two categories based on whether when it is divided by ‘2’ gives remainder ‘0’ or ‘1’. Odd numbers are the numbers which cannot be divided by ‘2’ or these numbers give remainder as 1 when they are divided by ‘2’. In other terms which can be written in the form of ‘2n+1’and Even numbers are numbers which can be divided by 2 i.e., these numbers give remainder as 0 when they are ... Read More

Advertisements