The Sieve of Eratosthenes algorithm is one of the most efficient ways to find prime numbers smaller than n when n is smaller than around 10 million. It follows a simple process of marking the multiples of already prime numbers as false i.e. non-prime numbers. In this article, we have a given number as 'num'. Our task is to find all the prime numbers less than or equal to num using the Sieve of Eratosthenes algorithm in C++. Example Here is an example to find prime numbers less than 10: Input: num = 10 Output: 2 3 5 7 ... Read More
cerr and clog are both objects of the stderr(standard error) stream, which is used to display error messages or diagnostics. In this article, we will learn the difference between these two in more detail. Further, the description of the cout object is also given to get a clearer picture. Unbuffered standard error stream (cerr) The cerr is the standard error stream, which is used to output the errors. This is also an instance of the ostream (as iostream means input/output stream) class. As cerr is unbuffered, therefore it's used when we need to display the error message instantly. It doesn't ... Read More
In C programming, when you pass an array by value, you are not sending the entire array. Instead of this, it passes a pointer to the first element. So, this shows functions directly work with an original array but do not copy. Note: If we make any changes to the array element, those changes will be reflected in the original array outside the function as well. Syntax There are two syntaxes for passing an array by value as follows: i. The syntax of array notation for passing array to function. void function_name(data_type array_name[], int size) { // Function ... Read More
In C++, a single character is represented using a single quotation (' ') while a string is represented using a double quotation (" "). To change the single character into a string, use approaches like string_constructor, push_back(), etc., that solve the conversion. Example Input: ch = 'A' Output: str = A // "A" So, character A is converted to a string. C++ provides various approaches to convert single character into string as follows: Using string constructor Using push_back() Using stringstream ... Read More
In programming, int and long are the part of primitive data type. The int stores the integer value while long stores the larger range of values like a whole number. In this article, we will see the differences between int and long data types. int (Integer) Data Type The keyword int representing the integer value. It store the both positive and negative values such as -1, 45, -78, 85, etc., but not fractional and decimal values. The value ranges from –2, 147, 483, 648 to 2, 147, 483, 647. Behavior of int in Different Languages Following is the list of ... Read More
In this article, we will learn to set a border for JCheckBox in Java. JCheckBox is a Swing component that is commonly used in user interface selection. Although it includes a default appearance, we can customize its look by setting borders in order to have a good visual effect. What is a JCheckBox? A JCheckBox is a component that extends JToggleButton, and an object of JCheckBox represents an option that can be checked or unchecked. Syntax The following is the syntax for JCheckBox initialization: JCheckBox Checkbox_name = new JCheckBox(); If there are two or more options, then any ... Read More
In this article, we will learn to set the shortcut key to a JButton in Java. In Swing-based applications, we can implement the addition of keyboard shortcuts to buttons to enable quicker navigation by the user. What is a JButton? A JButton is a subclass of AbstractButton, and it can be used to add platform-independent buttons to a Java Swing application. When the button is pressed or clicked, a JButton can generate an ActionListener interface; it can also generate the MouseListener and KeyListener interfaces. Setting the Shortcut Key for JButton We can also set the shortcut keys for a JButton ... Read More
In this article, we will learn to implement the word wrap JTableHeader of a JTable in Java. The Java Swing default JTableHeader does not support word wrapping. This is a problem if you have long column headers. We can implement this by customizing the DefaultTableModel class or the AbstractTableModel class. JTableHeader A JTableHeader is a subclass of the JComponent class. When we create a JTable object, the constructor creates a new JTableHeader object to manage the table component's header. Syntax The following is the syntax for JTableHeader Declaration: public class JTableHeader extends JComponent The JTableHeader object is associated with ... Read More
In this article, we will learn to read/parse a JSON array using Java. A JSON array is an ordered collection of values that are enclosed in square brackets, i.e., it begins with ‘[’ and ends with ‘]’. The values in the arrays are separated by ‘, ’ (comma). Sample JSON array The following is the syntax for JSON array initialization: { books": [ Java, JavaFX, Hbase, Cassandra, WebGL, JOGL] } Reading (Parsing) JSON array in Java The following are the different approaches for reading/parsing a JSON array in Java: JSON-Simple maven dependency ... Read More
DAG stands for Directed Acyclic Graph. It is a special type of graph where all edges are directed and there are no cyclic connections of edges. In this article, we will discuss how to check whether a graph is a DAG using Kahn’s algorithm (BFS based topological sorting). What is DAG? A DAG is a directed graph with no cycles. That means in this type graph it is not possible to start from any node and follow a sequence of edges such that you will return back to the starting node. DAGs are commonly used in applications like task ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP