In this article, we will learn to convert a string to a double in Java. Problem Statement Given a string representing a decimal number, convert it into a double in Java. The input string is guaranteed to be a valid numeric representation. Input: String str = "23.6"; Output: 23 Converting String to Double in Java The following are the different approaches for converting a string to a double in Java - Using Double.parseDouble() Using Double.valueOf() Using String to Double Constructor Using DecimalFormat ... Read More
To check if a graph is strongly connected or not, we need to check if for any pair of vertices u and v in the directed graph, there exists a directed path from u to v and a directed path from v to u. In this article, we have a directed graph with five vertices and its respective adjacency matrix. Our task is to check if the given graph is strongly connected or not. Example of Strongly Connected Graph The graph displayed in the figure below is an example of a strongly connected graph. In the above graph, ... Read More
In this article, we will understand how to generate a graph for a given fixed-degree sequence. The degree of each node is given in the form of an array. The graph generated will be an undirected graph where the degree of each node will correspond to the given degree array. Example The following example generates a graph and adjacency matrix for the given degree sequence: Input: Degree Sequence: {3, 2, 3, 2} => Degree(Node a) = 3, Degree(Node b) = 2, Degree(Node c) = 3, Degree(Node d) = 2 ... Read More
The Euler path is a path using which we can visit every edge exactly once in a graph. The same vertex can be used for multiple times. The source and destination nodes in the Euler path are different. If the source and destination node become the same, then the Eulerian path is also an Eulerian cycle. In this article, our task is to check if there exists an Eulerian path in the given undirected graph. Example of Eulerian Path The figure below displays an undirected graph and its respective adjacency matrix. As we can see there exists an Eulerian ... Read More
Passing an array by reference is a method of passing arrays to functions in C++ that allows the function to access and modify the original array without creating a copy. In this article, we will learn how to pass arrays by reference, the benefits of this approach, and provide examples. Passing an Array by Reference In the pass by reference approach, the address location of the first element of the array is passed to user defined functions. So, technically, we are passing the same array to that function without creating a copy. The changes made to the array ... Read More
Sorting of an array refer to the process of arranging the elements of the array in ascending or descending order. In this article, we will learn how to use the std::sort function from the C++ STL library to sort an array. In this problem, you are given an array of integers, and you need to arrange the elements in ascending order using std::sort. For example: // Input array int arr[] = {5, 2, 9, 1, 5, 6}; // Output {1, 2, 5, 5, 6, 9} // Explanation: The array is sorted in ascending order. C++ ... Read More
4 Dimensional ArrayThe 4 dimensional array is an array of 3 dimensional arrays. Each 3 dimensional array is an array of 2 dimensional arrays and each 2 dimensional array is an array of 1 dimensional arrays. In this article, we will learn all about 4 dimensional arrays, how to create them and how to access their elements with examples in both C and C++. Syntax to Create a 4D Array Following is the syntax for declaring a 4 dimensional array in C/C++: datatype array_name[dimension1][dimension2][dimension3][dimension4]; // Example int arr[3][2][3][4]; Example of a 4 Dimensional Array The ... Read More
In Java, formatted text refers to those text that has been processed and arranged according to a specific format. According to the article, we will use the printf() method to learn how to print the formatted text. Formatted Text using printf() Method In Java, to print the formatted output or text we have a printf() method. The printf() method allows us to format output to a java.io.PrintStream or java.io.PrintWriter. These classes also contain a method called format() which can produce the same results, so whatever we read here for the printf() method can also be applied to the format() method. ... Read More
C++ is a general-purpose and high-level programming language, which was created by Bjarne Stroustrup in the early 1980s. It is an extension of the C programming language, which means it has features of C (procedural programming) with the added feature of object-oriented programming. It has become a widely used language, especially in competitive programming and is supported on most platforms such as Windows, Linux, Unix, and macOS. Advantages of C++ Programming LanguageIn this article we will discuss the advantages of using C++ language: C++ is a highly portable language that supports multi-device and multi-platform application ... Read More
Calling a JavaScript function directly from C++ depends on the environment and the system; for this, make sure you have embedded a JavaScript engine or integrated C++ with JavaScript. In this article, we will be using Emscripten (C++ to JavaScript in WebAssembly) to call a JavaScript function from C++. For this, you have to compile the C++ program to WebAssembly using Emscripten and then call JavaScript functions from C++. So, first, create the C++ file with the header . C++ File Let's consider that this file name is saved as main.cpp. #include // here declared an external JS ... Read More