Print prime numbers from 1 to 100 in Java.

  Print prime numbers from 1 to 100 in Java.import java.util.Scanner; public class PrimeNumbers { public static void main(String[] args) { int count=0; System.out.print("Enter any number: "); Scanner sc=new Scanner(System.in); int num=sc.nextInt(); for(int i=2;i<num;i++) { if(num%i==0) { count++; } } if(count==0) { System.out.println("This number is Prime."); } else { System.out.println("This number is not Prime."); } } } Output:- Enter any number: 5 This number is Prime.
Read More

Collections Framwork in Java.

                                                                                 Collections Framework in Java What is Collection in Java? Collection: A Collection is a group of individual objects as a single entity. If you want to represent a group of individual objects as a single entity then we should go for Collection. e.g. Collection of pens. The collection is also known as Container. Collections are used to store, retrieve, manipulate, and communicate aggregate data. Using Collection we can perform many operations such as searching, sorting, insertion, manipulation, deletion etc. What Is a Collections Framework? A collections framework is a unified…
Read More

Object Oriented Programming Examples in Java.

Some real life Examples and Programming Examples of Object-oriented programming (OOP) concept in Java. 1 .Polymorphism : The process of representing one form(Task) in multiple forms(Different-Different ways) is known as Polymorphism. Real Life Example - Suppose if you are in class room that time you behave like a student, when you are in market at that time you behave like a customer, when you at your home at that time you behave like a son or daughter, Here one person present in different-different behaviors. Programming Example- Method Overloading and Method Overriding. 2. Abstraction : Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context. Real Life Examples - Abstraction shows only important things to the user and hides the internal details, for…
Read More

Perfect Number program in Java.

Perfect Number program in Java. What is Perfect Number?   Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128. import java.util.Scanner; class PerfectNumber { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("Enter your Number:"); int num=sc.nextInt(); int i=1, sum=0; while(i<num) { if(num%i==0) { sum=sum+i; } i++; } if(sum==num) { System.out.println("your number "+num+" is a perfect number."); } else { System.out.println("your number "+num+" is not a perfect number"); } } } Output: Enter your Number:6 your number 6 is a perfect number. Watch video of this program
Read More

Java Program to check Even or Odd number.

Java Program to check Even or Odd number. import java.util.Scanner; public class OddEvenNumber { public static void main(String arges[]) { System.out.print("Enter any number:"); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n%2==0) { System.out.println("This number is Even"); } else { System.out.println("This number is Odd"); } } } Output: Enter any number:10 This number is Even. Watch video of this program
Read More

Java program to find the divisors of a number.

Java program to find the divisors of a number. import java.util.Scanner; public class Divisors { public static void main(String[] args) { System.out.print("Enter any number:"); Scanner sc=new Scanner(System.in); int num=sc.nextInt(); System.out.println("The divisors of "+num+" are:"); for(int i=1;i
Read More

Java program to find factorial of a number.

Java program to find factorial of a number. import java.util.Scanner; public class Factorial { public static void main(String args[]) { int n, f = 1; System.out.print("Enter any number:"); Scanner sc = new Scanner(System.in); n = sc.nextInt(); for (int i = 1; i
Read More