My Blog
Articles related to programming, computer science, technology and research.

Java program to print unique words in a given line of text

14/05/2018 Categories: Strings. 1 Comment on Java program to print unique words in a given line of text

This java program reads a line of text from the user and prints out the unique words in ascending order.   We use TreeMap class from collections framework to store the frequency of each word in the given line of text and print out only the words with frequency 1, which will give us the […]

Read the rest of this entry »

Java program to print only unique characters in a string

14/05/2018 Categories: Strings. No Comments on Java program to print only unique characters in a string

This java program reads a string from the user, and prints out only the unique characters in the string in insertion order.   First we find out the frequency of each character in the string and then print out only the characters that have frequency as 1. To maintain the insertion order, we use LinkedHashMap […]

Read the rest of this entry »

Java program to print the frequency of characters in a string

14/05/2018 Categories: Strings. No Comments on Java program to print the frequency of characters in a string

This java program reads a string from the user, calculates frequency of each character in the strings and displays the character followed by its frequency in ascending order.   We can maintain the count of each character by using the Map interface from collections framework. To maintain the ascending order, we can use TreeMap class. […]

Read the rest of this entry »

Java program to ignore duplicates in a string and print each character only once in ascending order

14/05/2018 Categories: Strings. 1 Comment on Java program to ignore duplicates in a string and print each character only once in ascending order

This is a Java program that accepts a string from the user, ignores any duplicate characters and prints each character only once in ascending order.   We use TreeSet class from collections framework for printing the characters in ascending order.   The program is as follows:  

  If you want to display in […]

Read the rest of this entry »

Java program to display integers and their sum using StringTokenizer

08/06/2016 Categories: Strings. Comments Off on Java program to display integers and their sum using StringTokenizer

Java programĀ using StringTokenizer class, which reads a line of integers and then displays each integer and the sum of all integers.

Input and output for the above program is as follows: Enter a line of numbers: 2@3@1@4@5 Number is: 2 Number is: 3 Number is: 1 Number is: 4 Number is: 5 Sum of […]

Read the rest of this entry »

Java program for sorting a given list of names in ascending order

07/06/2016 Categories: Strings. Comments Off on Java program for sorting a given list of names in ascending order

Java programĀ for sorting a given list of names or strings in ascending order.

Input and output for the above program are as follows: Enter the value of n: 4 Enter strings: suresh mahesh dinesh ganesh Sorted list of strings is: dinesh ganesh mahesh suresh

Read the rest of this entry »

Java program that checks whether a given string is a palindrome or not

07/06/2016 Categories: Strings. 1 Comment on Java program that checks whether a given string is a palindrome or not

Java program that checks whether a given string is a palindrome or not.

Input and output for the above program is as follows: Enter a string: madam Entered string is a palindrome

Read the rest of this entry »
Scroll Up