# Category: Problem Solving

## Write a program to Find The Closest Number To 0

Write a program to Find The Closest Number To 0. public static int getClosestToZero(int a){ int num = a[0]; int absNum = Math.abs(num); for(int i = 1; i < a.length; ++i) { int newAbs = Math.abs(a[i]); if(newAbs < absNum) { absNum = newAbs; num = a[i]; } else if(newAbs==absNum) { if(num<a[i]) { num=a[i]; } }

## Write a java program to Count String Occurrences.

Obtain two strings from the user as input. Your program should count the number of occurrences of the second word of the second sentence in the first sentence as a output you need to find count string occurrences in a string. Return the count as output. Note – Consider case. The return type is the

## Write a java program to check Anagram.

Write a program to check whether the two given strings are anagrams. Note: Rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once is called Anagram.” returns an int. The method returns 1 if the 2 strings are anagrams. Else it returns -1.

## Write a java program to count Unique Characters in String.

Given a String as input, write a program to count and print the number of unique characters in it. If there are no unique characters in the string, the method returns -1 Input and Output Format: Input consists of a string. The output consists of an integer. Sample Input 1: HOWAREYOU Sample Output 1: 7

## Write a java program for ArrayList and Set Operations.

Write a program that performs the following actions: Read 2n integers as input & a set operator (of type char). Create two arraylists to store n elements in each arraylist. Write a functionÂ performSetOperationsÂ which accepts these two arraylist and the set operator as input. The function would perform the following set operations:. ‘+’ for SET-UNION ‘*’

## Write a java program to find Adjacent Swaps.

Write a Program that accepts a string as a parameter and returns the string with each pair of adjacent letters reversed. If the string has an odd number of letters, the last letter is unchanged. Input and Output Format: Input consists of a string with maximum size of 100 characters. Output consists of a single

## Write a java program to find Sum of Digits in a string

Write a Program that accepts a word as a parameter, extracts the digits within the string and returns its sum. Input and Output Format: Input consists of a string with maximum size of 100 characters. The output consists of a single string. Refer sample output for formatting specifications. Sample Input 1: abc12de4 Sample Output 1:

## Write a java program to check E-Mail Validation.

Write a java program to read a string and validate the given email-id as input. Validation Rules: 1. Ensure that there are at least 5 characters between ‘@’ and ‘.’ 2. There should be only one ‘.’ and one ‘@’ symbol. 3. The ‘.’ should be after the ‘@’ symbol. 4. There must be at

## Write a java program to find Symmetric Difference

Write a program to read two integer array and calculate the symmetric difference of the two arrays. Finally, Sort the array. Symmetric difference is the difference of A Union B and A Intersection B ie. [ (A U B) – (A ^ B)] Union operation merges the two arrays and makes sure that common elements

## Write a java program to find Day of Week.

Write a program to read a string containing date in DD/MM/YYYY format and prints the day of the week that date falls on. Return the day in the lowercase letter (Ex: Monday). Input and Output Format: Input consists of a string. The output consists of a string. Refer sample output for formatting specifications. Sample Input