Found 75 Articles for Campus Interview

Java Program to Create random strings

AmitDiwan
Updated on 29-Mar-2022 12:18:27

533 Views

In this article, we will understand how to create random strings. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −The size of the string is defined as: 10The desired output would be −Random string: ink1n1dodvAlgorithmStep 1 - START Step 2 - Declare an integer namely string_size, a string namely alpha_numeric and an object of StringBuilder namely string_builder. Step 3 - Define the values. Step 4 - Iterate for 10 times usinf a for-loop, generate a random value using the function Math.random() ... Read More

Java Program to Split a list into Two Halves

AmitDiwan
Updated on 29-Mar-2022 12:13:11

922 Views

In this article, we will understand how to split a list into two halves. A list is an ordered collection that allows us to store and access elements sequentially. It contains the index-based methods to insert, update, delete and search the elements. It can also have duplicate elements.Below is a demonstration of the same −Suppose our input is −Input list :[Java, Python, JavaScript, Shell, Scala]The desired output would be −The first half of the list is: [Java, Python] The second half of the list is: [JavaScript, Shell, Scala]AlgorithmStep 1 - START Step 2 - Declare three array list namely input_list, ... Read More

Java Program to split into a number of sub-strings

AmitDiwan
Updated on 29-Mar-2022 12:09:04

401 Views

In this article, we will understand how to splitting into a number of sub-strings. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). A part or a subset of string is called substring.Below is a demonstration of the same −Suppose our input is −Input string: JVMThe desired output would be −The substring list printed as an ArrayList : [J, JV, JVM, V, VM, M] The sub-strings after splitting is: (1) "J" (2) "JV" (3) "JVM" (4) "V" (5) "VM" (6) "M"AlgorithmStep 1 - START Step 2 - Declare a string namely ... Read More

Java Program to Print even length words

AmitDiwan
Updated on 29-Mar-2022 11:57:44

1K+ Views

In this article, we will understand how to print even length words. String is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabets or an integer or an special character.Below is a demonstration of the same −Suppose our input is −Input string: Java Programming are coolThe desired output would be −The words with even lengths are: Java coolAlgorithmStep 1 - START Step 2 - Declare a string namely input_string. Step 3 - Define the values. Step 4 - Iterate over the string usinf a for-loop, ... Read More

Java Program to Determine the Unicode Code Point at a given index

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

279 Views

In this article, we will understand how to determine the unicode code point at a given index. Each character is represented by a unicode code point. A code point is an integer value that uniquely identifies the given character. Unicode characters can be encoded using different encodings, like UTF-8 or UTF-16.Below is a demonstration of the same −Suppose our input is −Input String: Java Program Index value: 5The desired output would be −Unicode Point: 80AlgorithmStep 1 - START Step 2 - Declare a string value namely input_string and two integer values namely index and result Step 3 - Define the ... Read More

Java Program to Print first letter of each word using regex

AmitDiwan
Updated on 29-Mar-2022 11:36:28

334 Views

In this article, we will understand how to print first letter of each word using regex. A regular expression is a sequence of characters that forms a search pattern. A regular expression can be a single character, or a more complicated pattern.A regular expression helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data.Below is a demonstration of the same −Suppose our input is −Input String_1: Java Program Input String_2: Joy of learningThe desired output would be −Result_1: JP ... Read More

Java Program to Check Whether the Given String is Pangram

AmitDiwan
Updated on 29-Mar-2022 11:30:38

305 Views

In this article, we will understand how to check whether the given string is pangram. A string is a pangram string if it contains all the character of the alphabets ignoring the case of the alphabets.Below is a demonstration of the same −Suppose our input is −Input string: AbcdefghijklmnopqrstuvwxyzThe desired output would be −Yes, the string is a pangramAlgorithmStep 1 - START Step 2 - Declare a string value namely input_string. Step 3 - Define the values. Step 4 - Convert the input string to a character array. Step 5 - Iterate over the character of the array and check ... Read More

Java Program to Swap Pair of Characters

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

1K+ Views

In this article, we will understand how to swap pair of characters in Java. We will convert the given string to character array. This will allow us to swap pair of characters.Below is a demonstration of the same −Suppose our input is −Input string: Java programThe desired output would be −The string after swapping is: Javg proaramAlgorithmStep 1 - START Step 2 - Declare a string value namely input_string, a char array namely character, and a string object namely result. Step 3 - Define the values. Step 4 - Convert the string to character array. Step 5 - Swap the ... Read More

Java Program to Sort a String

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

2K+ 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

Java Program to Reverse a String Using Stacks

AmitDiwan
Updated on 29-Mar-2022 11:11:44

1K+ Views

In this article, we will understand how to reverse a string using stacks. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). The stack is a linear data structure that is used to store the collection of objects. It is based on Last-In-First-Out (LIFO).Below is a demonstration of the same −Suppose our input is −Input string: Java ProgramThe desired output would be −Reversed string: margorP avaJAlgorithmStep 1 - START Step 2 - Declare two string values namely input_string and result, a stack value namely stack, and a char value namely reverse. Step ... Read More

Advertisements