Reverse Words in a String in C++

Ravi Ranjan
Updated on 18-Jun-2025 19:19:54

6K+ Views

In this article, we have a string. Our task is to reverse the words in the given string. Here is an example of reversing the words of a string: Example The example below reverses the words of the given string: Input: "I am Viper" Output: Viper am I Here are the approaches to reverse the words of a string: Using Two Pointer Approach Using STL reverse() Function Using stringstream with Vector Using Recursive Approach ... Read More

C++ Program to Perform Finite State Automaton Based Search

Farhan Muhamed
Updated on 18-Jun-2025 19:18:27

798 Views

An automaton with a finite number of states is called a Finite Automaton. We can use a Finite State Automaton (FSA) to perform optimized pattern search operation on a string. This article will discuss how to implement a Finite State Automaton based search in C++. Problem Statement: Given two strings text[] and pattern[], we want to find all occurrences of the pattern in the text using a Finite State Automaton. // Input Strings text[] = "tutorialsPoint provides premium tutorials on various topics" pattern[] = "tutorials" // Output Pattern found at index 0 and 32 Finite State ... Read More

Check If Two Strings Are Anagram in Java

Shriansh Kumar
Updated on 18-Jun-2025 19:11:41

4K+ Views

An anagram is a word or phrase formed by rearranging the letters of two or more words. Suppose there are two strings. If both strings contain the same set of letters along with the same number of letters, regardless of their order, then we can say that both strings are anagrams; otherwise, not. Now, let's understand how we can find if two strings are anagrams or not in Java. How to Check if two Strings are Anagram? Follow the steps given below to solve the Anagram String problem: ... Read More

Java Nested Loops with Examples

Shriansh Kumar
Updated on 18-Jun-2025 19:09:16

2K+ Views

Loops in Java are called control statements because they decide the flow of execution of a program based on some condition. Java allows the nesting of loops. When we put a loop within another loop, then we call it a nested loop. Nested loops are used when we need to iterate through a matrix array and when we need to do any pattern-based questions. In this article, we are going to learn about Java nested loops with examples. Nested Loops in Java We can create nested loops for the following control statements in Java: ... Read More

Java Program to Reverse a Number

Shriansh Kumar
Updated on 18-Jun-2025 19:05:39

967 Views

For a given input number, write a Java program to reverse its digits. In reverse operation, we print the digits of given number from the last to start. The digit at the last position is swapped with the digit at the first position, the second last digit is swapped with second position digit and so on. Example Scenario: Input: number = 123456; Output: rev_number: 654321 How to Reverse a Number in Java? There are multiple ways to reverse the digits of a given number. We are going to discuss the following: Using ... Read More

What Happens If We Directly Call the run() Method in Java

Vivek Verma
Updated on 18-Jun-2025 19:00:48

261 Views

The run() method of the Thread class is called internally after the start() method is invoked to begin a new thread. However, if the run() method is called directly (without start()), it does not start a separate thread and executes within the current thread. The run() Method In Java, the run() method of the Thread class is used to define the sequence of actions that a thread will execute. This method will be invoked by the Java Virtual Machine (JVM) implicitly; we can also invoke this method explicitly in the current thread without calling the start() method. Note! The run() ... Read More

POSIX Character Classes in Java Regex

Maruthi Krishna
Updated on 18-Jun-2025 18:55:44

752 Views

In this article, we will learn about the p{ASCII} of the POSIX character class in Java regex. What is \p{ASCII}? In Java regex, \p{ASCII} POSIX character class matches any of the characters that fall within ASCII. ASCII (American Standard Code for Information Interchange) defines a character encoding standard consisting of 128 characters (0-127). This class matches the ASCII characters within the range of \x00-\x7F. Printable characters in the \p{ASCII} of the Java Regex are: Numbers (0 to 9) Uppercase letters (A to Z) Lowercase letters (a ... Read More

Print Elements of a HashMap in Java

Vivek Verma
Updated on 18-Jun-2025 18:53:34

3K+ Views

In Java, a HashMap is a subclass of the AbstractMap class and is used to store key-value pairs. Each key in the map is mapped to a single value in the map, and the keys are unique.Printing Java HashMap Elements  We can insert a key only once in a map, and duplicate keys are not allowed, but the value can be mapped to multiple keys. We can add the elements using the put() method of the HashMap class and iterate over the elements using the Iterator interface. Java HashMap provides various ways to print its elements as follows: ... Read More

Check If a Double or Float is NaN in C++

Aman Kumar
Updated on 18-Jun-2025 18:47:53

14K+ Views

In this article we will check whether a double or floating point number is NaN (Not a Number) in C++. Checking if a Double or Floating Point Number is NaN To check, we can utilise the isnan() method. The isnan() function is available in the cmath library. This function was introduced in C++ version 11. So From C++11 next, we can use this function. The isnan() function is used to determine whether a double or floating point number is not-a-number (NaN) value. Return true if num is NaN, false otherwise. C++ Program to Check Double or Float Number is NaN ... Read More

Assertions in C and C++

Aman Kumar
Updated on 18-Jun-2025 18:46:54

409 Views

What is an Assertions in C/C++? An assertion is a statement used to test assumptions made by the program. When an assertion fails, the program displays an error and stops. This is mainly used for debugging. In C and C++, assertions are handled using the assert() macro defined in the (C) or (C++) header file. Following is the declaration for assert() Macro. #include // in C // or #include in C++ assert(expression); The parameter of this assert() is expression: This can be a variable or any C/C++ expression. If ... Read More

Advertisements