Dear readers, today we create a program to check whether the given String is Palindrome or not. Following are the ways to do it. 1) Using Stack 2) Using Queue 3) Using for/while loop 1 Example : Palindrome check Using Queue in Java import java.util.Queue; import java.util.Scanner; import java.util.LinkedList; class PalindromeTest { public static void ..
Category : Java Interview Q&A
Dear readers, today we will create a Java Program to sum up all the elements of an array. his can be solved by looping through the array and add the value of the element in each iteration to variable sum. Sum of all elements of an array is 1 + 2 + 3 + 4 ..
In this program, you’ll learn to calculate the average of the given arrays in Java. 1. Program to Calculate Average Using Arrays public class Average { public static void main(String[] args) { double[] numArray = { 45.3, 67.5, -45.6, 20.34, 33.0, 45.6 }; double sum = 0.0; for (double num: numArray) { sum += num; ..
Dear readers today we read in article a Java program to count the vowels and consonants in a String. The program of counting the vowels and consonants in a given string Here we have two variables vcount and ccount to keep the count of vowels and consonants respectively. We have changed each chart of the ..
Dear readers, today we create a Java program, which is that we are detecting the occurrence of every character in a string. To do this we are first creating an array of size 256 (ASCII upper range), the idea here is to store a count that goes against the ASCII value of that character. For ..
Dear readers, we can create a Java program to sort array elements using bubble sort. The bubble sort algorithm is known as the simplest sorting algorithm. In the bubble sort algorithm, the array is traced from the first element to the last element. Here, the current element is compared with the next element. If the ..
Dear readers, today we read in this tutorial how each word in a string is inverted and the inverted string is displayed as the output. For example, if we input a string as “reverse the word of this string”, the output of the program would be: “Esther iht submerge seaht gnarts”. What is reverse string ..
In this program, we are asking the user to enter a count of strings that he wants to enter for sorting. After capturing the computation using the scanner class, we initialized a string array of input count size and then running for a loop to capture all strings input by the user. Once the strings ..
Dear readers, today we create a program which is find duplicate characters in a String and would display the count of them. Java Program to find duplicate Characters in a String using HashMap import java.util.HashMap; import java.util.Map; import java.util.Set; public class Details { public void countDupChars(String str){ //Create a HashMap Map<Character, Integer> map = new ..
Dear readers, today we will read in this tutorial char to String and String to char conversion in Java Program in easy way . Java Program to convert char to String You can two ways for char to String conversion. Method 1: Using toString() method Method 2: Usng valueOf() method class CharToStringDemo { public static ..