Month: June 2022
We consider the sequence of numbers in which a number is followed by the same number plus the sum of these digits. For example 34 is followed by 41 (41 = 34 + (3+4)). 41 is itself followed by 46 (46 = 41 + (4+1)). Two sequences with different starting . . . Read more
Check if a string is composed of parentheses and square brackets recursively in Java The program below identifies a string composed of parentheses ( ) and square brackets [ ]. A string of this type is considered correct : If it is an empty string or null If the string . . . Read more
The main difference between name() and toString() is that name() is a final method, so it cannot be overridden. The toString() method returns the same value that name() does by default, but toString() can be overridden by subclasses of Enum. 1. Using default name method : Output : 2. Overriding . . . Read more
1. Initialize a HashMap : 2. Iterate over keys : 3. Iterate over values : 4. Iterate over both key and value : 5. Full example : Output :
We can convert String to an int in java using Integer.parseInt() method. This method may throw NumberFormatException. We can also convert String into Integer by using Integer.valueOf() method which returns instance of Integer class. This method may throw NumberFormatException.