Showing posts with label Deficient Number. Show all posts
Showing posts with label Deficient Number. Show all posts

Deficient Number

 //Wap to accept a number and check it is Deficient number or not.

//A number is said to be a Deficient number if sum of the factors of the number is less than the number.

import java.util.*;

class deficient

{//class deficient opens

    public static void main(String[]args)

    {//main method opens

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter a no");

        int n=sc.nextInt();//variable n to accept the no

        int s=0;//variable s to store the sum of the factors

        for(int i=1;i<n;i++)

        {

            if(n%i==0)

            s=s+i;

        }

        if(s<n)

        System.out.println("It is a deficient no");

        else

        System.out.println("It is not a deficient no");

    }//main method closes

}//class closes


Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...