The standard input (stdin) can be represented by System.in in Java. The System.in is an instance of the InputStream class. It means that all its methods work on bytes, not Strings. To read any data from a keyboard, we can use either the Reader class or the Scanner class. Using Reader Class In Java, the Reader class is an abstract class belonging to the java.io package that is used for reading character streams. It is the superclass of all character input streams, such as "BufferedReader", "InputStreamReader", "FileReader", etc. Subclasses of Reader To use the functionality of the Reader class, use its ... Read More
This article will discuss how to convert a hexadecimal value to a byte value in Java. Before converting it to a byte, let's first understand what hexadecimal and byte values are. Hexadecimal Value In Java, a hexadecimal number is a base-16 number represented using the digits 0-9 and the letters A-F or a-f, where A-F represent the decimal values 10-15 respectively. The hexadecimal values are: 0x1A 0xFF 0x0A Byte Value In Java, a byte is a data type that can store whole numbers between the ... Read More
The given task is to find the number of days in a month of a particular year. To understand this, consider that if we can determine the maximum day value in a month, we can use that as the number of days in that month. To do this, we can use the GregorianCalendar class. It is a concrete subclass of the Calendar class, and it provides the standard calendar system used by most of the world. In Java, this GregorianCalendar can handle both the Gregorian calendar as well as Julian calendar. Following are the different ways to ... Read More
A set is a data structure that is used to store distinct values (meaning no two elements can have the same value) in ascending or descending order. Set for User-defined Data TypesWe can directly use sets for built-in data types, but for user-defined data types, values cannot be directly stored, because a set compares the elements to maintain order, but for user-defined data types such as array or struct, the compiler will not be able to perform a comparison between them. The set container is defined under the header file. So to use user-defined datatypes into a stack, we ... Read More
In some cases, especially in competitive programming, we may need to specify the minimum or maximum value of a specific datatype. In C++, each data type has a different memory range under which we can define and declare the value of that data type. But it becomes difficult to remember all the large ranges of each data type. So, C++ has introduced the macros that are used to represent the minimum and maximum range of some datatype. And some data types do not have macros for minimum values, because they are unsigned (means, hold only positive value). So, as their ... Read More
What is Fascinating Numbers? A Fascinating number is a number if the result of concatenation of the (original) number with its multiples of 2 and 3 contains all the digits from 1 to 9. For example, we have the number 192. Its product with 2 is 384, and with 3 is 576. Now concatenate (don't add) these with the original number: "192" + "384" + "576" = "192384576", which contains all the digits from 1 to 9 exactly once. Here are some other fascinating numbers, suchas: 192, 1920, 2019, 327, etc. Note: For a number to be a fascinating number, ... Read More
What is Evil Number? In mathematical terms, an Evil number is a number whose binary representation has exactly an even number of 1's present in it. For example, the binary representation of 3 is 0011. So the number 1's is even the number 3 is an evil number. A binary number is a number expressed in the base-2 numeral system, it is also known as the binary numeral system. It is always represented using two digits: 0 and 1. Each digit (0, 1, 2, 3, ...), character (a, A, b, c, D, ...Z), and symbol (@, #, $, ...) used ... Read More
What is Bouncy Number? In mathematical terms, a Bouncy number is a positive integer whose digits are neither in increasing nor in decreasing order. For example: 101, 102, 103, 104, 105, 106, 107, 108, 109, and 120 are the bouncy numbers, which digits does not follow any specific order. The bouncy number will always be unsorted, and there are no bouncy numbers between the range of 1 to 100 because numbers less than 100 can have only two digits that will be either increasing or decreasing order. Input & Output Scenarios The following input and output scenarios will implement the mathematical ... Read More
Yes, an Enum implements an Interface in Java. It can be useful when we need to implement business logic that is tightly coupled with a specific property of a given object or class. Before implementing the interface with an enum, let's discuss enums and interfaces in Java with a code snippet for better understanding. Enum in Java In Java, an Enum (i.e., an enumeration) is a special data type added in Java version 1.5. Enums are constants by default; the names of an enum type's fields are in uppercase letters. In the Java programming language, you can define an Enum ... Read More
This article will discuss the wait() and wait(long timeout) methods, along with a suitable example that explains when to call these methods in a thread in Java. The wait() Method In Java, the wait() method is used in multithreading and causes the current thread to "wait" until another thread calls notify() or notifyAll() on the same object. When the wait() method is called, the thread moves from the running to the waiting state and resumes only when notified, if not a deadlock will be formed. Note: Call the wait() method only when the thread should wait without any time limit. Following ... Read More