java
Two Sum leetcode solution in java
Problem of Two Sum leetcode Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Solution in java
Formatter class in java
At the core of Java’s support for creating formatted output is the Formatter class. It provides format conversions that let you display numbers, strings, and time and date in virtually any format The Formatter Constructors The Formatter class defines many constructors, which enable you to construct a Formatter in a variety of ways. Here is … Read more
Currency class in java
The Currency class encapsulates information about a currency. It defines no constructors Demonstrate Currency Output The Methods Defined by Currency Method Description String getCurrencyCode( ) Returns the code (as defined by ISO 4217) that describes the invoking currency. int getDefaultFractionDigits( ) Returns the number of digits after the decimal point … Read more
Timer and TimerTask class in java
Timer and TimerTask work together. Timer is the class that you will use to schedule a task for execution. The task being scheduled must be an instance of TimerTask. Thus, to schedule a task, you will first create a TimerTask object and then schedule it for execution using an instance of Timer TimerTask implements the … Read more
The Observer Interface in java
To observe an observable object, you must implement the Observer interface. This interface defines only the one method shown here: Here, observOb is the object being observed, and arg is the value passed by notifyObservers( ). The update( ) method is called when a change in the observed object takes place Demonstrate the Observable class … Read more
Random class in java
The Random class is a generator of pseudorandom numbers. These are called pseudorandom numbers because they are simply uniformly distributed sequences. Random defines the following constructors: Random( ) Random(long seed) The Methods Defined by Random Method Description boolean nextBoolean( ) Returns the next boolean random number. void nextBytes(byte … Read more
Locale class in java
The Locale class is instantiated to produce objects that describe a geographical or cultural region. It is one of several classes that provide you with the ability to write programs that can execute in different international environments. For example, the formats used to display dates, times, and numbers are different in various regions. The Locale … Read more