Server Side Programming Articles - Page 521 of 2650

C++ code to find corrected text after double vowel removal

Arnab Chakraborty
Updated on 29-Mar-2022 11:27:52

176 Views

Suppose we have a string S with n character. On a text editor, there is a strange rule. The word corrector of this text editor works in such a way that as long as there are two consecutive vowels in the word, it deletes the first vowel in a word. If there are no two consecutive vowels in the word, it is considered to be correct. We have to find corrected word from S. Here vowels are 'a', 'e', 'i' 'o', 'u' and 'y'.So, if the input is like S = "poor", then the output will be "por".StepsTo solve this, ... Read More

Java program to check whether the given string is pangram

AmitDiwan
Updated on 05-Nov-2024 22:03:46

727 Views

In this article, we will understand how to check whether the given string is a pangram in Java. A string is a pangram string if it contains all the characters of the alphabet ignoring the case of the alphabet. Here, we will be using two different approaches: using the main() method and using encapsulation. Problem Statement Given a string write a program in Java to find whether the string is pangram or not. Below is a demonstration of the same − Input  Input string: Abcdefghijklmnopqrstuvwxyz Output Yes, the string is a pangram Different approaches Following are the steps to check whether ... Read More

C++ code to count steps to reach final position by robot

Arnab Chakraborty
Updated on 29-Mar-2022 11:24:46

387 Views

Suppose we have two coordinates (x1, y1) and (x2, y2). A robot is at the point (x1, y1) and wants to go to the point (x2, y2). In a single step, the robot can move towards one cell to its 8 adjacent coordinates. We have to find minimal number of steps needed to reach the final position.So, if the input is like x1 = 3; y1 = 4; x2 = 6; y2 = 1;, then the output will be 3, becauseStepsTo solve this, we will follow these steps −return maximum of |x2 - x1| and |y2 - y1|ExampleLet us see ... Read More

C++ code to count numbers after division elements greater than half of array size

Arnab Chakraborty
Updated on 29-Mar-2022 11:20:32

171 Views

Suppose we have an array A with n elements. We have to find some non-zero integer d, such that such that, after each number in the array is divided by d, the number of positive values that are presented in the array is greater than or equal to the half of the array size. If there are multiple values of d that satisfy the condition. If there are multiple answers, return any one of them.So, if the input is like A = [10, 0, -7, 2, 6], then the output will be 4, because here n = 5 , so ... Read More

Java program to swap pair of characters

AmitDiwan
Updated on 09-Aug-2024 23:59:56

2K+ Views

In this article, we’ll learn how to swap pairs of characters in a Java string. We start with a simple method that converts the string into a character array, allowing us to swap characters directly. Then, we’ll explore an object-oriented approach where the swapping logic is encapsulated in a separate method. Both approaches highlight key Java concepts such as string manipulation and method encapsulation. Problem Statement Write a Java program to swap a pair of characters. Below is a demonstration of the same − Input  Input string: Java program Output The string after swapping is: Javg proaram Steps for basic ... Read More

C++ code to find who cannot give sufficient candies

Arnab Chakraborty
Updated on 29-Mar-2022 11:17:25

171 Views

Suppose we have two numbers a and b. There are a and b number of candies in Amal's and Bimal's hand. Amal offered 1 candy to Bimal and Bimal gave two candies to Amal, in the next turn Amal gave 3 candies and Bimal gave 4 and so on. This continued until the moment when one of them couldn’t give the right amount of candy. They don’t consider the candies they have got from the opponent, as their own. We have to find, who is the first can’t give the right amount of candy.So, if the input is like a ... Read More

Java Program to Sort a String

AmitDiwan
Updated on 29-Mar-2022 11:21:25

3K+ Views

In this article, we will understand how to sort a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). Strings are a sequence of charactersBelow is a demonstration of the same −Suppose our input is −Input string: javaprogramThe desired output would be −String after sorting is: [a, a, a, g, j, m, o, p, r, r, v]AlgorithmStep 1 - START Step 2 - Declare a string value namely input_string, a character array charArray, char value name temp and an int value namely string_size. Step 3 - Define the values. Step 4 ... Read More

C++ code to find minimum number starting from n in a game

Arnab Chakraborty
Updated on 29-Mar-2022 11:12:58

245 Views

Suppose we have a number n. In a game initially the value of n is v and the player is able to do the following operation zero or more times: Select a positive integer x that x < n and x is not a divisor of n, then subtract x from n. The goal of the player is to minimize the value of n in the end.So, if the input is like n = 8, then the output will be 1, because the player can select x = 3 in the first turn, then n becomes 5. We can then ... Read More

C++ code to find money after buying and selling shares

Arnab Chakraborty
Updated on 29-Mar-2022 11:11:01

338 Views

Suppose we have two arrays A of size n, and B of size m, and another number r. There are n opportunities to buy shares. The i-th of them allows to buy as many shares as we want, ith share price is A[i]. And also there are m opportunities to sell shares. The i-th of them allows to sell as many shares as we want, sell price of ith share is B[i]. We can't sell more shares than we have. If we have r amount of money and no existing share, we have to find the maximum number of money ... Read More

Java program to reverse a string using stacks

Aishwarya Naglot
Updated on 05-Jun-2025 11:53:14

2K+ Views

Stack is a linear data structure where we can store elements. It uses the LIFO (last in, first out) principle, which means the item we add last will be the first one to be removed. In this article, we will understand how to reverse a string using stacks. Let's take an example: Input: String input_string = "Java Program"; Output: String reversed_string = "margorP avaJ"; Ways to Reverse a String Using Stacks Below are the different approaches to reverse a string using stacks: Reverse a string using built-in stack methods ... Read More

Advertisements