Check Whether a Number is a Narcissistic Number in Java

Vivek Verma
Updated on 28-Aug-2025 15:47:12

3K+ Views

What is a Narcissistic Number? A number is said to be a Narcissistic number, only if the addition (or sum) of the value of each digit raised to the power of the total number of digits available in the original number is equal to the original number. Examples of narcissistic numbers, such as 153, 1634, 54748, etc. All single-digit numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) are Narcissistic numbers because the power of 1 of any digit will be the digit itself. The following input and output scenarios will help you understand the problem and calculation ... Read More

Compiling a C++ Program with GCC

Vivek Verma
Updated on 28-Aug-2025 15:43:45

31K+ Views

To compile a C++ program with GCC, we need to download GCC or install the g++ compiler on our system. Otherwise, you will not be able to compile C++ code using GCC. What is GCC? The GCC is a tool chain that compiles code. It stands for GNU Compiler Collection, which was developed by the GNU project. The GCC supports various programming languages such as C, C++, Go, etc. Specific to the C++ language, the GCC provides the g++ compiler, which is developed or designed to compile the C++ source code into executable programs. Note: When the C++ program compiles ... Read More

Type Safe Enum in Java

raja
Updated on 28-Aug-2025 14:47:43

2K+ Views

In Java, an enum is a special class that represents a "group of constants" that cannot be changed, just like a "final variables". Java provides an enum keyword to create an enum, and inside the class, the constants are written in uppercase letters and separated by commas (, ). Syntax to create an enum in Java: enum EnumName { CONST1, CONST2, CONST3 // ... } Here, enum: A predefined keyword used to define an enum. EnumName: The name ... Read More

Synchronize a Run Method in Java

Vivek Verma
Updated on 28-Aug-2025 14:46:52

3K+ Views

Yes, we can synchronize a run() method in Java using the synchronized keyword before this method. If this method is synchronized, only one thread can execute this on a given instance of the object at any point in time. Here is a code snippet that shows how to define the run() method as synchronized: @Override synchronized run(){ //code implementation } Here, the @Override annotation specifies that the run() method overrides a method from the Runnable interface, and synchronized is a reserved keyword in Java used to define a method or block as synchronized. Synchronization of a run() ... Read More

132 Pattern in C++

Vivek Verma
Updated on 28-Aug-2025 14:10:10

481 Views

The 132 pattern indicates that, as the digits in "132" in any given value, the middle element should be greater than the last and first elements. Similarly, the last element must be greater than the first element. To check 132 patterns in C++, we will use the Array data structure. We have given an array nums[] of size S. Our task is to check whether the array elements at indices i, j, and k are such that i < j < k and nums[j] < nums[k] and nums[i] < nums[k]. If any three elements at positions i < j < k ... Read More

Print All Distinct Elements of a Given Integer Array in Python

Yaswanth Varma
Updated on 28-Aug-2025 13:50:01

1K+ Views

The distinct elements are the values that appears only once or uniquely in the array. When working with the array we will come across the repeated or duplicate values. In this article, we are going to print all the distinct elements of a given array. Identifying and printing these distinct elements is a common task to avoid the unexpected results. This can be achieved by using the Python built-in tools like sets and dictionaries. Using Python set() Function In this approach we are using Python set() function, which removes all the duplicate value from the list because a ... Read More

Display Hostname and IP Address in Python

Yaswanth Varma
Updated on 28-Aug-2025 13:47:10

2K+ Views

In this article, we are going to learn how to display the hostname and IP address. Generally, the devices that connect to a network are identified by two things: Hostname: It is the name assigned to the device on a network. It helps users to identify devices in a human-readable format (e.g, mypc, desktop-pc, etc.) IP Address: It is the numerical address assigned to each device on a network, used to locate and communicate with that device. Python provides the built-in socket module for achieving this task, which provides access to various ... Read More

Print Initials of a Name with Last Name in Full using Python

Yaswanth Varma
Updated on 28-Aug-2025 13:46:33

5K+ Views

In this article, we are going to learn about how to print the initials of a name with last name in full. For example, If we consider the applications like resumes or media references, it represents the person name using initials followed by the last name like instead of writing "Sai Vamsi Srinivas", we might write "S.V.Srinivas". This kind of formatting improves the readability and ensures the important part of the name(last name) is fully visible. Using Python split() and join() Methods The Python split() method is used to split all the words in the string by ... Read More

Split Even and Odd Elements into Two Different Lists in Python

Yaswanth Varma
Updated on 28-Aug-2025 13:45:35

24K+ Views

In this article, we are going to learn about splitting the even and odd elements into two different lists. This involves looping each element in a list and checking whether it is divisible by 2. Even numbers are those that gives the remainder '0' when divided by 2, while the odd numbers leaves a remainder '1'. Using Python append() Method The Python append() method is used to add the new object to a list. It accepts an object as a argument and inserts it at the end of the existing list. Syntax Following is the syntax of Python ... Read More

SequenceMatcher in Python for Longest Common Substring

Yaswanth Varma
Updated on 28-Aug-2025 13:44:57

1K+ Views

The SequenceMatcher class is the part of the Python difflib module. It is used to compare sequence (such as lists or strings) and finds the similarities between them. The task is to find the Longest Common Substring, i.e, the longest sequence of the characters that appears contiguously in both strings. which is different from the Longest Common Subsequence, where the characters may appear in the same order but not repeatedly. Using find_longest_match() Method The find_longest_match() method is used to find the longest matching sequence of elements between two sequences. It is the part of the Python difflib module. ... Read More

Advertisements