Core java
22 JanuaryJava program to subtract two matrices
In this post, we will see how to subtract two matrices in java.I am giving example for 33 matrix. You can extend it to nn matrices. import java.util.Scanner; public class MatrixOperator { public static void main(String args[]) { int i, j; int mat1[][] = new int[3][3]; int mat2[][] = new int[3][3]; int res[][] = new […]
22 JanuaryConvert celsius to fahrenheit in java
In this tutorial, we will see simple java program to convert celsius to fahrenheit in java. You can convert celsius to fahrenheit using this formula. fh = (1.8*cen) + 32; import java.util.Scanner; public class TempConvertor { public static void main(String args[]) { float cen; double fh; Scanner scanner = new Scanner(System.in); System.out.print("Enter Temperature in Centigrade […]
22 JanuaryConvert fahrenheit to celsius in java
In this tutorial, we will see simple java program to convert fahrenheit to celsius in java. You can convert fahrenheit to celsius using this formula. cel = (fh-32) / 1.8; import java.util.Scanner; public class TempConvertor { public static void main(String args[]) { float fh; double cel; Scanner scanner = new Scanner(System.in); System.out.print("Enter Temperature in Fahrenheit […]
20 JanuaryJava program to delete words from sentence
In this post, we will see how to delete words from the sentence. You can just use String’s replaceAll method to replace the word with empty String(""). Here is simple java program to delete words from the sentence. import java.util.Scanner; public class StringOperator { public static void main(String args[]) { String str, word; Scanner scan […]
20 JanuaryJava 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 JanuaryJava 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 JanuaryJava 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 JanuaryProgram 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 JanuaryJava 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 […]