Found 33676 Articles for Programming

Capitalize last letter and Lowercase first letter of a word in Java

Mr. Satyabrata
Updated on 05-Jan-2023 11:56:58

7K+ Views

String is a sequence of character values. In Java, Strings are considered as objects. We have a String class provided by Java for creating and manipulating strings. We have to convert the first letter of the word to lowercase and last letter of the word to uppercase. In this article we will see how the first and last letter can be converted into lower and upper case respectively. Let’s explore. To Show You Some Instances Instance-1 Suppose the input string is “Hello” After converting the first letter to lower and last letter to capital, the new string will be “hellO” ... Read More

Find if sum of odd or even array elements are smaller in Java

Mr. Satyabrata
Updated on 05-Jan-2023 11:51:05

1K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the sum of elements which is even and sum of elements which is odd in an array and compare their sum and check which one is smaller. A number is said to be even if it is divisible by 2 else it is called an odd number. Note − The array must be an integer array. Let’s explore the article to see how it can be done by using Java programming language. ... Read More

Check Average of Odd Elements or Even Elements are Greater in Java

Mr. Satyabrata
Updated on 05-Jan-2023 11:45:21

643 Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to find the sum of all even and odd numbers in a given array and compare them to see which one is greater. Note − The array must be an integer array. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the original array is {14, 49, 55, 67, 72, 82} After finding average of sum of even and ... Read More

Check if Array is Free From 0 and Negative Number in Java

Mr. Satyabrata
Updated on 05-Jan-2023 11:39:58

2K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to check and confirm the array is free from 0 and negative numbers. Let us say that an array contains 0 or a negative element then the result should pop up that "Array contains 0 or a negative number." Otherwise, the result should be "Array doesn’t contain 0 or a negative number." Note − The array must be an integer array. Let’s explore the article to see how it can be done by using ... Read More

Arrange Negative Array Elements Before Positive Elements in Java

Mr. Satyabrata
Updated on 05-Jan-2023 11:33:51

1K+ Views

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type. As per the problem statement we have to arrange all elements of array such that negative elements are present before positive elements. If a number is greater than 0 then it is called as positive number, if less than 0 then it is called as negative number. Note − The array must be an integer array. Let’s explore the article to see how it can be done by using Java programming language. To Show You Some Instances Instance-1 Suppose the ... Read More

How to search for an array element in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:25:13

25K+ Views

In TypeScript, while working with the array, we often require to search for a particular element. To search for an element, either we can use the naive approach using the for loop or some built-in method such as the find() or indexOf() method. Also, we will learn to find the particular object in the array based on the object property. Using the for-of Loop to Search a Particular Element in The Array The naive approach to searching for an element is using linear search. In linear search, we need to iterate through the array using the for loop and check ... Read More

How to reverse the String in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:22:05

11K+ Views

This tutorial demonstrates multiple ways to reverse a string in TypeScript. At first, reversing the string problem looks easy, but what if someone asks you to explain the different approaches to reversing a string in TypeScript? For example, what if the interviewer asks to reverse the words of the string rather than reversing every character of the string? Here, we will learn to reverse every character or word of the string in TypeScript. Using the for-of Loop to Reverse a String in TypeScript The naive approach to reverse the string uses the normal for loop or for-of loop. Here, we ... Read More

How to replace substring in string in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:18:52

1K+ Views

Sometimes, we need to replace a substring with a new string or any particular character while working with TypeScript. The simple way to replace the substring or part of the string is to use the replace() method. Here, we will create a custom algorithm to replace the string for the interview purpose of the beginners. However, we will also see the replace() method at last in this tutorial. Create the Custom Algorithm to Replace the Substring We will use the for loop to iterate through the main string in this part. We will use the substr() method of the string ... Read More

How to join multiple arrays in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:33:23

4K+ Views

The array stores the elements of the different data types in TypeScript. It is a collection of elements we can use it to store and access data whenever required. While working with multiple arrays, we need to combine two or more arrays. There are several ways to combine multiple arrays in TypeScript, and we will look through all ways in this TypeScript tutorial. Also, we will discuss when we should use which way is the best at last. Uing The For Loop to Join The Two Arrays We can follow the traditional way of using the for-of loop to join ... Read More

What is Type Assertion in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:00:27

5K+ Views

Type assertion is a mechanism in TypeScript that informs the compiler of the variable type. We can override the type using a type assertion if TypeScript finds that the assignment is wrong. We must be certain that we are correct since the assignment is always legitimate when we employ a type assertion. If not, our program might not operate properly. Declaratively informing the compiler that we intend to regard the item as a distinct type is known as type assertion. Using this, we can regard any as a number or a number as a string. When moving code from JavaScript ... Read More

Advertisements