Java Program to Delete all Vowel Characters from String

  • Java program to remove all vowel alphabets from a string using replaceAll() method.
  • Java program to delete all vowels from a string without using any library function.

In this java program, we have to delete all occurrences of vowel characters from a given string and then print it on screen.

Java Program to Print Pascal Triangle

  • Write a java program to print pascal triangle till N rows.

In this java program, we have to print the pascal triangle on screen till N rows. We will take number of rows as input from user. Before jumping into java program, here is the brief introduction of pascal triangle.

Java Program to Calculate Compound Interest

  • Java program to find the Compound interest.

In this java program to calculate compound interest, we first take amount, rate of interest and duration in year as input from user and use following equation to calculate compound interest.

Java Program to Check Two Strings are Anagram or Not

  • Java program to check two strings are anagrams or not.

In this java program, we have to check whether two strings are anagram or not and print the result on screen. Two strings are anagram of each other, if we can rearrange characters of one string to form another string.

Java Program to Calculate Simple Interest

  • Java program to find the simple interest

In this java program to calculate simple interest, we first take amount, duration in year and rate of interest as input from user and use following equation to calculate simple interest.

Java Program to Find Frequency of Each Character in a String

  • Java program to count the occurrence of each character if a string.

In this java program, we have to count the frequency of occurrence of each character of a string and then print it on screen.

Java Program to Find Transpose of a Matrix

  • Java program to print transpose of a matrix using for loop.

In this java program, we have to find the transpose matrix of a given M x N matrix. To find the transpose of a matrix, we will swap a row with corresponding columns, like first row will become first column of transpose matrix and vice versa. The transpose of matrix A is written AT.

Java Program to Reverse Words of a Sentence

  • Java program to reverse a sentence.
  • Write a java program to reverse words of a sentence.

Given a sentence, we have to reverse the sequence of words in given sentences. Words of the given sentence are separated by one or multiple space characters.

Java Program to Count Words in a Sentence

  • Java program to count words in a sentence using split method.

To count the number of words in a sentence, we first take a sentence as input from user and store it in a String object. Words in a sentence are separated by space character(" "), hence we can use space as a delimiter to split given sentence into words. To split a string to multiple words separated by spaces, we will call split() method.

Java Program to Delete all Spaces from a String

  • Java program to remove all space characters from a string using replaceAll() method.

In this java program, we have to delete all occurrences of space characters from a given string and then print it on screen.

For Example,
Input String : Tech Crash Course
Output String : TechCrashCourse

Java program to remove all spaces from string using replaceAll method

In this java program, we will first take a string as input from user and store it in a String object "str". To delete all space characters from str, we will call replaceAll() method of String class. This method replaces any occurrence of space characters(including multiple adjacent space characters) with "". We are using "[ ]" regular expression, which matches with any space character.

package com.tcc.java.programs;

import java.util.Scanner;

/**
 * Java Program to remove all spaces from String
 */
public class DeleteSpaces {
    public static void main(String args[]) {
        String str, output;
        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter a String");
        str = scanner.nextLine();

        // Deleting all space characters from given string
        // usnig replaceAll method
        output = str.replaceAll("[ ]", "");

        System.out.println("Output String\n" + output);
    }
}
Output
Enter a String
I love  Java  Programming
Output String
IloveJavaProgramming
Enter a String
Java Programm     to remove spaces
Output String
JavaProgrammtoremovespaces