karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 2 of 143

Java program to merge duplicates of a List with TreeSet

karthikeya Boyini
karthikeya Boyini
Updated on 30-Oct-2024 678 Views

In this article, we will learn to merge duplicate elements from a List in Java by using a TreeSet. This program will take a List of strings containing duplicate values, transfer the elements into a TreeSet, and display the unique, sorted elements. Using a TreeSet is ideal here because it automatically removes duplicates and orders the elements in natural order. Problem Statement Write a Java program to remove duplicate elements from a list using a TreeSet. The program should take a list with repeated elements, convert it into a TreeSet to eliminate duplicates, and display the unique, sorted elements. Input ...

Read More

Java program to sort a List in case sensitive order

karthikeya Boyini
karthikeya Boyini
Updated on 29-Oct-2024 1K+ Views

In this article, we will learn to sort a List in case-sensitive order in Java. Sorting in case-sensitive order places uppercase letters before lowercase letters (e.g., 'A' before 'a'), meaning that uppercase letters are prioritized in sorting. This program uses Java’s built-in Collections.sort method to arrange elements in this specific order.  Problem Statement Given a list of mixed uppercase and lowercase letters, write a Java program that sorts the list in a case-sensitive order. Input { "P", "W", "g", "K", "H", "t", "E" } Output List = [P, W, g, K, H, t, E] Case Sensitive Sort = [E, H, ...

Read More

Java program to find the LCM of two numbers

karthikeya Boyini
karthikeya Boyini
Updated on 23-Oct-2024 9K+ Views

In this article, we will learn to find the LCM of two numbers using Java. L.C.M. or Least Common Multiple of two values is the smallest positive value which is the multiple of both values. For example, multiples of 3 and 4 are: 3 → 3, 6, 9, 12, 15 ... 4 → 4, 8, 12, 16, 20 ... The smallest multiple of both is 12, hence the LCM of 3 and 4 is 12.We will learn through two different methods to solve this: an incremental method and a formula-based approach using the Greatest Common Divisor (GCD).  Problem Statement Write ...

Read More

Java program to add long integers and check for overflow

karthikeya Boyini
karthikeya Boyini
Updated on 16-Oct-2024 1K+ Views

In this article, we will add two long integers in Java and check if the sum causes an overflow, which happens when the result exceeds the maximum value that a long data type can hold,  defined by the Long class as Long.MAX_VALUE. If the sum goes beyond this limit, an exception will be thrown to handle the overflow. Otherwise, the sum will be displayed as the result. Steps to add long integers and check for overflow Following are the steps to add long integers and check for overflow − First, we will define two long integers ...

Read More

Java program to check if the string contains any character in the given set of characters

karthikeya Boyini
karthikeya Boyini
Updated on 15-Oct-2024 1K+ Views

In this article, we will learn to check if the string contains any character in the given set of characters in Java. We will iterate over the string and compare each character to a set of characters that we want to search for. If any match is found, the program will print the character and confirm that it is present in the string. Problem Statement Write a program in Java to check if the string contains any character in the given set of characters − Input str = abcde chSearch = 'b', 'c' Output Character b found in string abcde ...

Read More

Java program to remove the leading and trailing quotes from a string

karthikeya Boyini
karthikeya Boyini
Updated on 19-Sep-2024 3K+ Views

In Java, handling strings with quotes can be managed by checking and manipulating the string’s start and end. This example demonstrates how to remove double quotes from both the beginning and end of a string. Problem Statement Given a string enclosed in double quotes, write a Java program to remove these enclosing quotes. The result must be the original string without the enclosing double quotes. Input String with double quotes= "Demo Text" Output String after removing double quotes = Demo Text Steps to remove the leading and trailing quotes from a string Below are the steps to remove the leading ...

Read More

Java program to find whether given character is vowel or consonant

karthikeya Boyini
karthikeya Boyini
Updated on 13-Sep-2024 14K+ Views

In this article, we will learn to find whether a given character is a vowel or consonant using Java. In the English alphabet, the characters 'a', 'e', 'i', 'o', and 'u' are vowels and the remaining letters are consonants. To find whether the given letter is a vowel or consonant. Using a loop and or operator verify whether the given character is 'a' or 'e' or 'i' or 'o' or 'u' else it is consonant. Steps to find whether given character is vowel or consonant Following are the steps to find whether given character is a vowel or consonant− ...

Read More

Java program to create a HashMap and add key-value pairs

karthikeya Boyini
karthikeya Boyini
Updated on 05-Sep-2024 2K+ Views

In this article, we will write a Java program to create a HashMap and add key-value pairs. We will be using the HashMap class we can import HashMap class form java.util package. A HashMap is a collection that stores data in the form of key-value pairs, allowing quick retrieval of values based on their keys. We'll also see how to display the elements stored in the HashMap using an iterator in our given program. Problem Statement Write a program in Java to create a HashMap and add key-value pairs − Output Belt: 600Wallet: 700Bag: 1100 Steps to create a HashMap and add ...

Read More

Java program to get random letters

karthikeya Boyini
karthikeya Boyini
Updated on 05-Sep-2024 2K+ Views

In this article, we will learn to write a program in Java to get the random letters in both lowercase and uppercase. We will be using Random class from java.util package.The program will first create random lowercase letters by selecting them from the alphabet, and then it will generate random uppercase letters in a similar way.  Problem Statement Write a program in Java to get the random letters both uppercase and lower case. Below is the demostration − Output Lowercase random letters...dlhjsUppercase random letters...BKIZN Step to get random letters Following are the steps to get the random letter using Java ...

Read More

Java program to calculate distance light travels

karthikeya Boyini
karthikeya Boyini
Updated on 27-Aug-2024 2K+ Views

In this article, we will demonstrate how to calculate the distance light travels in one year using Java. We will use the Demo class and the main method to perform this calculation. Speed of light: 186000Days = 365dist = speed * seconds Problem Statement Write a Java program to calculate the total distance that light travels in a year, given that the speed of light is 186, 000 miles per second. Output Light travels: 5865696000000 miles Steps to calculate distance light travels Following are the steps to calculate the distance light travels − Initialize the Demo class.Define ...

Read More
Showing 11–20 of 1,421 articles
« Prev 1 2 3 4 5 143 Next »
Advertisements