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 reverse the array inplace

18/10/2016 Categories: Arrays. 2 Comments on Java program to reverse the array inplace

Following program reads an array of elements and reverses the array in place i.e., without using any temporary array:

  Input and output for the above program are as follows:

 

Read the rest of this entry »

Java program to find the maximum and minimum element in an array

18/10/2016 Categories: Arrays. No Comments on Java program to find the maximum and minimum element in an array

Following program reads array elements from the user and finds out the maximum, minimum elements in the array:

  Input and output for the above program are as follows:

 

Read the rest of this entry »

Java program to find a given number is an Armstrong number or not

18/10/2016 Categories: Basic. No Comments on Java program to find a given number is an Armstrong number or not

Armstrong number is one in which the sum of the cubes of individual digits is same as the given number. For example if you take the number 153, (1^3) + (5^3) + (3^3) = 153. Following program reads a number from the user and finds out whether it is an Armstrong number or not:

[…]

Read the rest of this entry »

Java program to find a given number is palindrome or not

18/10/2016 Categories: Basic. No Comments on Java program to find a given number is palindrome or not

A palindrome is one which is same after reversing it. For example, if you take a number like 1221, after reversing it, it is again 1221. Following program reads a number from the user and finds out whether it is a palindrome or not:

  Input and output for the above program are as […]

Read the rest of this entry »

Java program to find the reverse of a given number

18/10/2016 Categories: Basic. No Comments on Java program to find the reverse of a given number

Following program reads a number from the user and prints the reverse of that number:

  Input and output for the above program are as follows:

 

Read the rest of this entry »

Java program to find the factorial of a number using recursion

18/10/2016 Categories: Basic. No Comments on Java program to find the factorial of a number using recursion

Following program reads a number form the user and prints its factorial using recursion:

  Input and output for the above program are as follows:

 

Read the rest of this entry »
Scroll Up