Nancy Den has Published 330 Articles

How to check whether the given date represents weekend in Java

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

992 Views

At first, display the current date:LocalDate date = LocalDate.now();Now, get the day of week from the above Date (current date):DayOfWeek day = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK));On the basis of the above result, use SWITCH to check for the current day. If the day is SATURDAY/SUNDAY, then it’s Weekend.Exampleimport java.time.DayOfWeek; import java.time.temporal.ChronoField; import java.time.LocalDate; ... Read More

What is StringJoiner class in Java 8?

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

188 Views

The StringJoiner class in Java 8 constructs a sequence of characters. This sequence is separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.The following are the constructors of the StringJoiner class:StringJoiner(CharSequence delimiter): This constructor constructs a StringJoiner with no characters in it ... Read More

How to count days between two dates in Java

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

1K+ Views

Let us first set two dates:LocalDate date1 = LocalDate.of(2019, 4, 16); LocalDate date2 = date1.with(Month.MAY).withDayOfMonth(04);Now, count the dates between both the above dates using between():int numDays = Period.between(date1, date2).getDays();Exampleimport java.time.LocalDate; import java.time.Month; import java.time.Period; public class Demo {    public static void main(String[] argv) {       LocalDate date1 ... Read More

StringJoiner toString() method in Java 8

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

198 Views

The toString() method of the StringJoiner class in Java8 is used to return the string representation of the StringJoiner.The syntax of the toString() method is as follows:String toString()To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The following is an example to implement StringJoiner toString() method in ... Read More

Java Program to generate random number with restrictions

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

745 Views

To generate random number with resctrictions, here we are taking an example of a phone number from India with the country code 91.First, we have set the first 2 numbers i.e. the country code. The variables are declared for each digit. We have also fixed the first digit of the ... Read More

Java Program to get the prime numbers with BigInteger type

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

439 Views

A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Here, we have the BigInteger type, which has operations for modular arithmetic, GCD calculation, primality testing, prime generation, etc.At first, we have set the value to 0 and then considered ... Read More

Memory-mapped I/O in 8085 Microprocessor

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

7K+ Views

It is possible to address an I/O port as if it were a memory location. For example, let us say, the chip select pin of an I/O port chip is activated when address = FFF0H, IO/M* = 0, and RD* = 0. This is shown in the following fig.In this ... Read More

C++ Program to Generate Random Numbers Using Multiply with Carry Method

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

208 Views

The multiply-with-carry method is a variant of the add-with-carry generator introduced by Marsaglia and Zaman (1991). The main advantages of this method are that it invokes simple computer integer arithmetic and leads to very fast generation of sequences of random numbers with immense periods, ranging from around 260 to 22000000.In ... Read More

Java Program to parse a mathematical expression and operators

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

2K+ Views

At first, we have set the mathematical expressions:String one = "10+15*20-5/5"; String two = "3+5-6"; String three = "9+2*(6-3+7)";To parse mathematical expression, use Nashorn JavaScript in Java i.e. scripting. Nashorn invoke dynamics feature, introduced in Java 7 to improve performance.For scripting, use the ScriptEngineManager class for the engine:ScriptEngineManager scriptEngineManager = ... Read More

The add() method in Java Stream.Builder

Nancy Den

Nancy Den

Updated on 30-Jul-2019 22:30:25

378 Views

Use the add() method to insert elements in the Stream.Builder. The element to be added is a parameter for the add().The following is the syntax:default Stream.Builder add(T t)Here, t is the element to be added.Import the following package for the Stream.Builder class in Java:import java.util.stream.Stream;At first, create Stream.Builder:Stream.Builder builder = ... Read More

Advertisements