Core java
19 JanuaryHow 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 JanuaryJava 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, […]
19 JanuaryJava program to calculate average marks
In this post, we will see simple java program to find average and percentage marks. We have taken average and percentage of five subject marks below. import java.util.Scanner; public class MarksCalculator { public static void main(String args[]) { int markArray[] = new int[5]; int i; float sum=0; float average, percentage; Scanner scan = new Scanner(System.in); […]
19 JanuaryJava program to make simple calculator
In this post, we will see how to create a simple calculator in java. This calculator program performs 4 basic operatios – Addition, Substraction, Multiplication and division.It uses Switch case to choose operation you want to perform. import java.util.Scanner; public class Calculator { public static void main(String args[]) { float num1, num2, result; char operation, […]
19 JanuaryJava Program to Check Whether a Character is Alphabet or Not
This tutorial provides Java Program to Check Whether a Character is Alphabet or Not. import java.util.Scanner; public class AlphabetFinder { public static void main(String args[]) { char character; Scanner scanner = new Scanner(System.in); System.out.print("Enter a Character : "); character = scanner.next().charAt(0); if((character>='a' && character<='z') || (character>='A' && character<='Z')){ System.out.print(character + " is an alphabet."); }else{ […]
19 JanuaryJava program to check leap year
In this post, we will see how to check leap year. import java.util.Scanner; public class LeapYearFinder { public static void main(String args[]) { int year; Scanner scanner = new Scanner(System.in); System.out.print("Enter Year : "); year = scanner.nextInt(); if((year%4 == 0) && (year%100!=0)){ System.out.print(year+" is a Leap Year"); }else if(year%100 == 0){ System.out.print(year+" is not a […]
19 JanuaryJava Program to check a Character is Vowel or Consonant
In this post, we will see how to check a Character is Vowel or Consonant. You just need to check if character is part of set {a,A,e,E,i,I,o,O,u,U}.If it is part of set then it is Vowel else Consonant. import java.util.Scanner; public class VowelFinder { public static void main(String args[]) { char character; Scanner sacnner = […]
18 JanuaryEven odd program in java
In this post,we will see how to check if number is even odd. It is one of the basic programs of Java programming language. import java.util.Scanner; public class EvenOddFinder { public static void main(String args[]) { int num; Scanner scanner = new Scanner(System.in); System.out.print("Enter a Number : "); num = scanner.nextInt(); if(num%2 == 0) { […]
18 JanuaryJava Program to add two numbers
In this post, we will see how to add two numbers in java. This is the most basic program of java programming language. import java.util.Scanner; public class Calculator { public static void main(String args[]) { int num1, num2, sum; // Taking input from user Scanner scanner = new Scanner(System.in); System.out.print("Enter two numbers : "); num1 […]