Print a Character N Times Without Using Loop, Recursion or Goto in C++

Aman Kumar
Updated on 16-May-2025 16:58:12

1K+ Views

In this article, we will see how to print a character n times without using loops and recursion in C++. Input/Output Scenario Let's see following input output scenario − Input : n = 10, c = 'i' Output : iiiiiiiiii Input : n = 5, character = 'j' Output : jjjjj Using String Constructor Here, using the string constructor in C++ to print a character n times: It allows initialization of a string with multiple copies of a specific character by passing the number of times and the character itself as arguments. Example In this C++ example, we ... Read More

Check If a Point Lies Inside or Outside a Circle in C++

Aman Kumar
Updated on 16-May-2025 16:57:30

295 Views

In this articles, we implements a C++ Program to check if a point d lies inside or outside a circle defined by points a, b, c in a plane using the following equation: s = (x-xt)^2 + (y-yt)^2 – r*r Where equation contains the following points: x, y: Any point in the plane. xt, yt: Center of the circle. r: Radius of the circle. s: The difference between the squared distance and ( r^2 ). If s is equal to 0, the ... Read More

Implement Gift Wrapping Algorithm in Two Dimensions using C++

Aman Kumar
Updated on 16-May-2025 16:56:07

536 Views

Gift Wrapping AlgorithmThe Gift Wrapping algorithm is also known as Jarvis's march. It is a method for calculating the convex hull of a set of points in a plane. It is essential to find the smallest convex polygon that encloses all the points. Why We Use Gift Wrapping Algorithm? Below are the following reasons to use this algorithm: Easy to Understand: It work like wrapping a string around points. Good for Small Data Sets: When fewer points make up the convex hull. Accurate: Never misses a point ... Read More

C++ Program to Implement Cartesian Tree

Aman Kumar
Updated on 16-May-2025 16:54:51

441 Views

Cartesian Tree in C++A Cartesian tree is a binary tree derived from a sequence of distinct numbers. To construct a Cartesian tree, set its root to be the minimum number in the sequence, and then recursively construct its left and right subtrees from the subsequence before and after this number. A Cartesian tree is a tree data structure that obeys the following structural invariants: The tree follows the min (or max) heap property - each node is less than or greater than its children. An inorder traversal of the nodes causes the values in the same order in which they arise in the initial series. Let's construct a max-heap ... Read More

Create a Class Without a Name in Java

Shriansh Kumar
Updated on 16-May-2025 15:51:21

1K+ Views

Yes, we can create a class without a name in Java using the anonymous class. It is a type of inner class which does not have a name and whose instance is created at the time of the creation of the class itself. You can create this class in a single statement using the new keyword. Creating multiple instances of this class is not allowed. You can use anonymous classes in case where you need to override methods of a class or an interface for a one-time use, and you don't want to create a separate named class for it. ... Read More

Why String Class is Immutable or Final in Java

Shriansh Kumar
Updated on 16-May-2025 15:48:37

9K+ Views

The general meaning of immutable is something that cannot be changed or modified after creation. In Java, a string is immutable; we cannot change the object itself, but we can change the reference to the object. The string is made final to not allow others to extend and modify it. When you modify a string, a new copy of the string with your modifications is created. This article will explain what a String is and why it is immutable and final in Java. What is a String? Like other object-oriented programming languages, almost every component of Java is an object, ... Read More

Use Except Clause with Multiple Exceptions in Python

Sarika Singh
Updated on 16-May-2025 14:47:49

3K+ Views

Using "except" Clause with Multiple Exceptions It is possible to define multiple exceptions with the same except clause. It means that if the Python interpreter finds a matching exception, then it will execute the code written under the except clause. Syntax In general, the syntax for multiple exceptions is as follows - Except(Exception1, Exception2, …ExceptionN) as e: When we define the except clause in this way, we expect the same code to throw different exceptions. Also, we want to take action in each case. Example In this example, we are trying to add an integer and a string, which is not ... Read More

Catch Multiple Exceptions in One Line Except Block in Python

Sarika Singh
Updated on 16-May-2025 14:39:26

449 Views

In Python, instead of writing separate except blocks for each exception, you can handle multiple exceptions together in a single except block by specifying them as a tuple. In this example, we are catching both ValueError and TypeError using a single except block - try: x = int("abc") # Raises ValueError y = x + "5" # Would raise TypeError if above line did not error except (ValueError, TypeError) as e: print("Caught an exception:", e) The above program will generate the following error ... Read More

What are Runtime Errors in Python

Sarika Singh
Updated on 16-May-2025 14:29:26

845 Views

RuntimeErrors in Python are a type of built-in exception that occurs during the execution of a program. They usually indicate a problem that arises during runtime and is not necessarily syntax-related or caused by external factors.When an error is detected, and that error doesn't fall into any other specific category of exceptions (or errors), Python throws a runtime error. Raising a RuntimeError manuallyTypically, a Runtime Error will be generated implicitly. But we can raise a custom runtime error manually, using the raise statement. ExampleIn this example, we are purposely raising a RuntimeError using the raise statement to indicate an unexpected condition in ... Read More

Print All Keys of a Dictionary in Python

Sarika Singh
Updated on 16-May-2025 10:46:37

107K+ Views

A Python dictionary is an unordered collection of data values. It contains a key-value pair, in contrast to other data structures that only include one value per entry. In this article, we are going to see the various ways to print all the keys of a dictionary in Python. Using dict.keys() Method Python's dict.keys() method can be used to retrieve the dictionary keys, which can be printed using the print() function. This method returns a list object, which contains every key in the dictionary. The dictionary elements can be accessed using the dict.keys() method, just like we do with a list ... Read More

Advertisements