• 20 January

    Java program to remove vowels from String

    In this tutorial we will see how to remove vowels from String in java. [toc] Using replaceAll() method We will use String’s replaceAll() method to remove vowels from String. import java.util.Scanner; public class StringOperator { public static void main(String args[]) { String str1, str2; Scanner scan = new Scanner(System.in); System.out.print("Enter a String : "); str1 […]

  • 20 January

    Java program to calculate arithmetic mean

    In this tutorial, we will see simple java program to calculate arithmetic mean. Here is simple algorithm to calculate arithmetic mean. Calculate sum of elements in the array Divide it by total number of element in the array. import java.util.Scanner; public class ArithMeanCalc { public static void main(String args[]) { int cnt, i, sum=0, mean; […]

  • 20 January

    Java program to count positive, zero and negative numbers

    In this post, we will see Java program to count positive, zero and negative numbers import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { int contp=0, cntn=0, cntz=0, i; int arr[] = new int[10]; Scanner scan = new Scanner(System.in); System.out.print("Enter 10 Numbers : "); for(i=0; i<10; i++){ arr[i] = scan.nextInt(); } for(i=0; […]

  • 20 January

    Program to find frequency of characters in a string in java

    In this tutorial, we will see simple program to find frequency of characters in a string in java. There are multiple ways to solve this proble. Let’s see one by one. [toc] Using counter array Here is the algorithm for the same. Initialize counter array of 256 length Iterate over String and increase count by […]

  • 20 January

    Java program to count number of words in sentence

    In this tutorial, we will see a simple java program to count number of words in sentence. import java.util.Scanner; public class StringOperator { public static int countWordsinStr(String str){ int count = 1; for(int i=0; i<=str.length()-1; i++){ if(str.charAt(i) == ' ' && str.charAt(i+1)!=' '){ count++; } } return count; } public static void main(String args[]){ String […]

  • 20 January

    Java program to print Diamond pattern

    In this tutorial, we will see java program to print diamond pattern. import java.util.Scanner; public class DiamondPattPrinter { public static void main(String args[]) { int cnt, c, k, space=1; Scanner scan = new Scanner(System.in); System.out.print("Enter count/number of Rows for Diamond pattern : "); cnt = scan.nextInt(); space = cnt-1; for(k=1; k<=cnt; k++){ for(c=1; c<=space; c++){ […]

  • 20 January

    Java program to print Fibonacci Series

    In this tutorial, we will print fibonacci series. According to wikipedia: In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:[1][2] 0,1,1,2,3,5,8,13,21,34,55,89,144.. Here is simple program to print […]

  • 19 January

    How to Compare Two Strings in Java

    In this post, we will see how to compare two String in java. As you might know, String implements Comparable interface, you can use compareTo method to compare two String in java. import java.util.Scanner; public class StringComparator { public static void main(String args[]) { String str1, str2; Scanner scan = new Scanner(System.in); System.out.print("Enter First String […]

  • 19 January

    Java program for sum of digits of number

    In this post, we will see how to find sum of digits of number in java. You can find unit’s place digit by number%10, add it to the total and divide the number by 10 to remove the unit’s place. import java.util.Scanner; public class DigitAdditionCalc { public static void main(String args[]) { int number, remdr=0, […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.