Implement a Java program to count the number of vowels and consonants in a string.

Here’s a Java program to count the number of vowels and consonants in a string: import java.util.Scanner; public class VowelConsonant { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(“Enter a string: “); String str = scanner.nextLine(); int vowelCount = 0, consonantCount = 0; str = str.toLowerCase(); for (int i = 0; … Read more

Write a Java program to check if a given string is a valid palindrome permutation.

Here’s a Java program to check if a given string is a valid palindrome permutation: import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class PalindromePermutation { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(“Enter a string: “); String str = scanner.nextLine(); boolean isValidPalindromePermutation = checkPalindromePermutation(str); if (isValidPalindromePermutation) { System.out.println(str + ” is … Read more

Implement a Java program to find the intersection of two arrays.

Here’s a Java program to find the intersection of two arrays: import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Intersection { public static void main(String[] args) { int[] arr1 = new int[5]; int[] arr2 = new int[5]; Scanner scanner = new Scanner(System.in); System.out.println(“Enter 5 numbers for the first array: “); for (int i = 0; … Read more

Implement a Java program to check if a number is Armstrong or not.

Here’s a Java program to check if a number is Armstrong or not: import java.util.Scanner; public class ArmstrongNumber { public static void main(String[] args) { int num, originalNum, remainder, result = 0; Scanner scanner = new Scanner(System.in); System.out.print(“Enter a number: “); num = scanner.nextInt(); originalNum = num; while (originalNum != 0) { remainder = originalNum … Read more

Implement a Java program to find the GCD (Greatest Common Divisor) of two numbers.

Here’s a Java program to find the GCD (Greatest Common Divisor) of two numbers: import java.util.Scanner; public class GCD { public static void main(String[] args) { int num1, num2, gcd; Scanner scanner = new Scanner(System.in); System.out.print(“Enter the first number: “); num1 = scanner.nextInt(); System.out.print(“Enter the second number: “); num2 = scanner.nextInt(); gcd = findGCD(num1, num2); … Read more

Write a Java program to convert a decimal number to binary.

Here’s a Java program to convert a decimal number to binary: import java.util.Scanner; public class DecimalToBinary { public static void main(String[] args) { int decimalNum; Scanner scanner = new Scanner(System.in); System.out.print(“Enter a decimal number: “); decimalNum = scanner.nextInt(); String binaryNum = convertToBinary(decimalNum); System.out.println(“Binary equivalent: ” + binaryNum); } public static String convertToBinary(int decimalNum) { String … Read more

Implement a Java program to remove duplicates from an array.

Here’s a Java program to remove duplicates from an array: import java.util.Arrays; import java.util.Scanner; public class RemoveDuplicates { public static void main(String[] args) { int[] arr = new int[5]; Scanner scanner = new Scanner(System.in); System.out.println(“Enter 5 numbers: “); for (int i = 0; i < 5; i++) { arr[i] = scanner.nextInt(); } int[] newArr = ... Read more

Write a Java program to reverse a number.

Here’s a Java program to reverse a number: import java.util.Scanner; public class ReverseNumber { public static void main(String[] args) { int num, reversedNum = 0; Scanner scanner = new Scanner(System.in); System.out.print(“Enter a number: “); num = scanner.nextInt(); while (num != 0) { int digit = num % 10; reversedNum = reversedNum * 10 + digit; … Read more

Write a Java program to find the sum of digits of a given number.

Here’s a Java program to find the sum of digits of a given number: import java.util.Scanner; public class SumOfDigits { public static void main(String[] args) { int num, sum = 0; Scanner scanner = new Scanner(System.in); System.out.print(“Enter a number: “); num = scanner.nextInt(); while (num > 0) { int digit = num % 10; sum … Read more