cin is an object of the input stream and is used to take input from input streams like files, console, etc. cout is an object of the output stream that is used to show output. Basically, cin is an input statement while cout is an output statement.They also use different operators. cin uses the insertion operator( >> ) while cout uses the extraction operator( >), which helps to extract the input from the cin and stores it in a variable. It automatically skips the whitespaces (spaces, tabs, newlines) until a special method like getline() is used. Syntax Here is the ... Read More
When we start programming then printing different star patterns helps us build our logic and problem-solving skills. One of the easiest and beginner patterns is the hollow rectangle pattern. In this article, we are going to learn how we can print the hollow rectangle pattern using different approaches in Python. Hollow Rectangle Pattern A Hollow rectangle pattern is a rectangle-shaped pattern printing of stars where the stars are present only on the boundaries of the rectangle. The rectangle is hollow, i.e., the stars are printed only on the boundaries of the rectangle, while the inner area remains empty. ***** ... Read More
This article will discuss how to print the first character of each word in a given string. For example, if we have the string "Hello John", the output should be H J. In Java, the String class is used to represent character strings. All string literals in a Java program are implemented as instances of the String class. Strings in Java are immutable, which means that once a string is created, its value cannot be changed. To print the first character of each word in a String, we have the following approaches - Using split() ... Read More
In Java, ArrayList and HashSet are the most important classes of the Collection Framework. Both are used to "store collections of elements", but they are used for different purposes and have different characteristics. ArrayList is an "ordered collection" that allows duplicate elements, while HashSet is an "unordered collection" that does not allow duplicates. ArrayList vs HashSet in Java Here are some key differences between ArrayList and HashSet in Java: Key ArrayList HashSet Implementation ArrayList is the implementation of the List interface. HashSet, on the other hand, is the implementation of a set interface. ... Read More
String representation of numbers is nothing but converting numeric values into their corresponding string values using methods like toString(). In Java, this can be done by calling the toString() method on wrapper classes such as Integer, Float, and Double. The toString() method is an important method of Object class and it can be used to return the string or textual representation of an object. The object class's toString() method returns a string as the name of the specified object's class which is followed by ?@' sign and the hashcode of the object (java.lang.String;@36f72f09) String Representation Using toString() Method To get ... Read More
This article will discuss how to check if a string ends with a specific substring, which means we need to verify whether the last part of the string matches a given sequence of characters or not. For example, if the given input string values are "Gaint", "allegiant", "applicant", "combatant", "elephant", and if the substring is "ant", the result would be true for all the given values. A String is an object that represents an immutable sequence of characters and cannot be changed once created. The java.lang.String class can be used to create a string object. There are several ways to ... Read More
Initializing a Boolean Array in Java refers to the process of assigning values (allocating memory) to the Boolean array for the first time. We can initialize an array or any variable - Either at the time of creation. Or, later in the program, using the assignment operator when we are just defining it initially. A Boolean array can be used to store only Boolean values (i.e., either true or false), and the "default value" of each element in a Boolean array is false. In some cases, we may need to initialize all ... Read More
In the 0-1 knapsack problem, a set of items is given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is as large as possible. What is Branch and Bound Algorithm?The branch and bound algorithm breaks the given problem into multiple sub-problems and then uses a bounding function. It eliminates only those solutions that cannot provide optimal solutions. In this article, we will discuss how to solve the 0-1 knapsack problem ... Read More
The multiply-with-carry method is a variant of the add-with-carry generator introduced by Marsaglia and Zaman (1991). The main advantages of this method are that it invokes simple computer integer arithmetic and leads to a very fast generation of sequences of random numbers with immense periods, ranging from around 260 to 22000000. In this article, our task is to generate random numbers using the multiply-with-carry method. Here is the formula of multiply-with-carry method: Multiply With Carry (MWC) Formula The multiply-with-carry formula is as follows: Xn = (a * Xn-1 + Cn-1) mod 232 Cn = (a * Xn-1 + Cn-1) ... Read More
Python 3.0 was released in December 2008. It was designed to rectify certain flaws in earlier versions. Python 3.0 doesn’t provide backward compatibility. That means a Python program written using version 2.x syntax doesn’t execute under the Python 3.x interpreter. Version 2.7 is the final major release in the Python 2.x series. The guiding principle of Python 3 was: "reduce feature duplication by removing old ways of doing things". Although there are quite a few differences in usage of these two versions, the most obvious ones are mentioned below - Print Statement Vs Function print is a keyword in Python ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP