Found 2619 Articles for Java

Find the Time Taken Finish Processing of given Processes

Neetika Khandelwal
Updated on 22-Aug-2023 17:31:50

37 Views

Given are N processes and two N−sized arrays, arr1[] and arr2[]. A process's time in the critical section is recorded in arr1[], and it’s time to finish processing after leaving the critical part is recorded in arr2. The goal is to determine how long it will take for each process to finish processing (both inside and outside of the critical section) in any given order. Input Output Scenarios Assume we have 3 arrays as shown below Input N = 3, arr1[] = {1, 4, 3}, arr2[] = {2, 3, 1} Output 9 The first process, at ... Read More

Find the Order of Execution of given N Processes in Round Robin Scheduling

Neetika Khandelwal
Updated on 22-Aug-2023 17:24:03

240 Views

In this article, you will learn about how to find the order of execution for the given N processes in the Round Robin Scheduling algorithm. But before starting with the code, let’s understand a bit about how this algorithm works. Round Robin Scheduling is a popular CPU scheduling algorithm used in operating systems to allocate CPU time to multiple processes in a fair and efficient manner. In this blog, we will explore how round−robin scheduling works, its advantages and disadvantages, and provide an example to help you understand the concept better. What is Round Robin Scheduling? Round Robin Scheduling is ... Read More

Set the Leftmost Unset Bit

Vanshika Sood
Updated on 27-Oct-2023 15:56:21

220 Views

This article seeks a method for setting a given number's leftmost unset bit. The first unset bit after the most significant set bit is considered the leftmost unset bit. Problem Statement Given a number n, the task is to set the left most bit of the binary expansion of the number that is unset. All the other bits should be left unchanged. If all the bits of the original number are already set, return the number. Examples Input: 46 Output: 62 Explanation Binary Expansion of 46 = 101110. Left most unset bit is 101110. Upon setting the underlined ... Read More

Java Program for Longest subsequence of a number having same left and right rotation

Shubham Vora
Updated on 17-Aug-2023 17:16:20

126 Views

In this problem, we need to find the length of the longest subsequence having the same left and right rotations. We can solve the problem using the brute-force approach, finding all possible subsequences of the given string and checking each subsequence one by one to see if it has the same left and right rotation. We find the maximum length of such subsequence. The problem with this approach is that it is very time-consuming as its time complexity is O(2N). So, we will learn to write optimized code in this approach. Problem statement – We have given string str containing ... Read More

Java Program for Closest Prime Number

Mr. Satyabrata
Updated on 17-Aug-2023 17:50:14

715 Views

A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. Prime numbers are an essential concept in mathematics and computer science. They are integers that are only divisible by 1 and themselves. Finding prime numbers is an important task in many algorithms, and there are several methods to determine if a number is prime. One such problem is finding the closest prime number to a given number. Here, we will explore how to find the closest possible prime number of any number. Let's start! For instance Given integer ... Read More

How to Read a File into an ArrayList in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:45:16

2K+ Views

In Java, an ArrayList is a resizable array, which is implemented as part of the Java Collections Framework. It is a dynamic data structure that can hold any type of objects, including primitive types such as integers and characters. As per the problem statement we have to read a file into an ArrayList. First and foremost we will take the path of the file as input and then we will apply different method to read the file. Let's start! For instance Suppose the input file is “myfile.txt”. After reading the content of the file, the result ... Read More

How to Convert Timestamp to Date in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:38:41

7K+ Views

Java, Timestamp can be converted Date by using Date class. Date class is present in java.util package. The constructor of the Date class receives a long value as an argument. Since the constructor of the Date class requires a long value, we need to convert the Timestamp object into a long value using the getTime() method of the TimeStamp class. Let's deep dive into this article, to know how it can be done by using Java programming language. To show you with instance Suppose the timestamp is 06/01/2023. Then corresponding Date is “Fri Jan 06 ... Read More

How to Convert Char to Int in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:35:59

415 Views

In Java, smaller datatype can be converted to bigger datatype. Here, we will see how to convert char datatype to int datatype. The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65, 535 inclusive). The int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. Let's deep dive into this article, to know how it can be done by using Java programming language. For instance Suppose the given ... Read More

Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 2

Mr. Satyabrata
Updated on 17-Aug-2023 17:33:03

157 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 0. Let's start! For instance Suppose we have 4*4 matrix i.e. 4 rows and 4 columns. After performing the operation on matrix, the result will be: Enter the size of the matrix: ... Read More

Java Program to Create a Matrix and Fill it With Prime Numbers

Mr. Satyabrata
Updated on 17-Aug-2023 17:29:42

331 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to create an empty matrix and fill that matrix with the prime numbers starting from the smallest prime number i.e. 2. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In simpler terms, a prime number is a ... Read More

Advertisements