• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Java

Solve any Factor Program in 10 minutes

  • Categories Java, Iterative Statements, For & While

Watch our video on Solve any Factor Program in 10 minutes in Java – Click Here

1 . Find if a number is prime number. prime number is a number divisible by 1 and itself e.g 5 is a primt number as it has factor only 1,5

import java.util.*;
public class PrimeNum
{
   public static void main(String args[])
   {
       Scanner sc =new Scanner(System.in);
       int count=0;
       System.out.println("enter a number");
       int n= sc.nextInt( );
       for(int i=1;i<=n;i++)
       {
          if(n%i==0)
            count++;
       }
       if(count==2)
         System.out.println("Yes");
       else
         System.out.println("No");
   }
}

2 . Find if a number is a composite number. Composite number is a number which has more than one factor(excluding 1 and itself) e.g 8=2, 4=2 factors

import java.util.*;
public class compositeNo
{
   public static void main(String args[])
   {
      Scanner sc =new Scanner(System.in);
      int count=0;
      System.out.println("enter a number");
      int n= sc.nextInt( );
      for(int i=1;i<=n;i++) { if(n%i==0) count++; } if(count>3)
         System.out.println("Yes");
      else
         System.out.println("No");
   }
}

3 . Find if a number is a perfect number. A perfect number is number which is equal to sum of its divisor or factor except itself e.g. 6=1+2+3

import java.util.*;
public class perfectNo
{
   public static void main(String args[])
   {
      Scanner sc =new Scanner(System.in);
      int sum=0;
      System.out.println("enter a number");
      int n= sc.nextInt( );
      for(int i=1;i<n;i++)
      {
         if(n%i==0)
           sum= sum+i;
      }
      if(sum==n)
         System.out.println("Yes");
      else
         System.out.println("No");
   }
}

4 . Find if a number is an Abundant number. Here sum of factor is greater then the number. itself e.g. 12 factor 1,2,3,4,6=16>12

import java.util.*;
public class AbundantNo
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
int sum=0;
System.out.println("enter a number");
int n= sc.nextInt( );
for(int i=1;i<n;i++)
{
if(n%i==0)
sum= sum+i;
}
if(sum>n)
System.out.println("Yes");
else
System.out.println("No");
}
}

5 . Find if number is a Deficient number. Here sum of factor is less than the no itself. e.g. 21 factor 1,3,7=11<21

import java.util.*;
public class DeficientNo
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
int sum=0;
System.out.println("enter a number");
int n= sc.nextInt( );
for(int i=1;i<n;i++)
{
if(n%i==0)
sum= sum+i;
}
if(sum<n)
System.out.println("Yes");
else
System.out.println("No");
}
}

6 . Find if number is a Pronic number. Pronic No is the product of two consecutive integers, n(n+1). e.g. 56=7×8

import java.util.*;
public class PronicNo
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
int fact=0;
System.out.println("enter a number");
int n= sc.nextInt( );
for(int i=1;i<n;i++)
{
if(i*(i+1)==n)
fact=i;
}
if(fact!=0)
System.out.println("Yes");
else
System.out.println("No");
}
}
  • Share:
author avatar
Simply Coding

Previous post

2D array in Java
July 3, 2021

Next post

Constructor Programs
July 3, 2021

You may also like

Single Linked List Programs in Java
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
Constructor Programs
3 July, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now