Sunday, 19 November 2017

Practice Programs on String in java

Given below are all the possible programs that will help you get a good grasp on String concept in java. (Update in Progress)

Note: Follow all the business rules where applicable.

  1. Write a method that takes a String and calculates the total number of characters in the String. Business Rules :- 
    Rule 1 : If any special characters is present in the string , print -1. Rule 2 : String should contain only alphanumeric values and white spaces.
  2. Write a method which takes a string as input and returns true if its a valid IP address and false if not a valid IP.
    Business Rules :-                                                                                                                          Rule 1 : IP address should be like 10.10.23.56
    Rule 2 : All the digit must be between 0 to 255 except for the first digit which is 1 to 255.
    Rule 3 : Total 4 numbers would be there separated by only dots.
    Rule 4 : All the fields must be either dot or digits(no white space or symbols or alphabets allowed).
  3. Write a method that accepts a string and returns the total number of vowels in that string.
  4. Write a method that takes a string array and returns the count of palindromes in the string array.
  5. Write a method that will accept a string and will return the string after removing all characters other than alphabets.
  6. Write a method which accepts a string(ex. This is a pen and is used to write) and returns a list<int> where the index of all occurrences of "is" is stored. 
  7. Write a method that will take two strings and will return an integer which is the frequency of first string in second string .
    Input1:- is
    Input2:-He is a good boy,but his brother is not.
    Output:- 2
  8. Write a method that will take a string and will remove duplicate characters keeping only the first occurrence.
    Input:- Kolkataaaaa   Output:- Kolat
  9. Write a method that will take a string and will return an int array that contains the length of the largest and smallest words.
  10. Write a method that will take a string which will be the password for a very secured account.
    Business Rules:-The string should be maximum 10 characters long,minimum 8 characters long, should have a minimum 1 special character, 1 uppercase character , 1 lowercase character and 1 digit. The string should not start with digit or special symbols. No space is allowed. If all conditions satisfy return true and otherwise false.

No comments:

Post a Comment

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.