Difference Between cin and cout Streams in C++

Akansha Kumari
Updated on 05-May-2025 17:05:21

17K+ Views

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

Python Program to Print Hollow Rectangle Pattern

AYUSH MISHRA
Updated on 05-May-2025 15:44:25

2K+ Views

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

Print First Character of Each Word in a String in Java

Vivek Verma
Updated on 05-May-2025 15:10:03

7K+ Views

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

Difference Between ArrayList and HashSet in Java

Vivek Verma
Updated on 05-May-2025 14:47:43

16K+ Views

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

Get String Representation of Numbers Using toString in Java

Vivek Verma
Updated on 05-May-2025 14:35:24

799 Views

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

Check If String Ends With Specific Substring in Java

Vivek Verma
Updated on 05-May-2025 14:19:02

1K+ Views

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

Initialize a Boolean Array in Java

Vivek Verma
Updated on 05-May-2025 13:46:37

25K+ Views

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

0-1 Knapsack Problem Using Branch and Bound in C/C++

Ravi Ranjan
Updated on 05-May-2025 12:29:17

4K+ Views

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

Generate Random Numbers Using Multiply with Carry Method in C++

Ravi Ranjan
Updated on 05-May-2025 12:28:21

420 Views

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

Key Differences Between Python 2.7.x and Python 3.x

Sumana Challa
Updated on 02-May-2025 21:40:20

534 Views

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

Advertisements