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

Abundant Number

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

//A number is said to be Abundant if sum of the factors of the number is greater than the number.

import java.util.*;

class abundent

{//class abundent 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 a no//12

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

        for(int i=1;i<n;i++)//1//2//3//4//5//6//7//8//9//10//11//12false

        {

            if(n%i==0)//12%1==0 t//12%2==0 t//12%3==0 t//12%4==0 t//12%5==0 f//12%6==0 t//12%11==0f

            s=s+i;//0+1=1//1+2=3//3+3=6//6+4=10//10+6=16

        }

        if(s>n)//16>12 true

        System.out.println("It is an abundent no");

        else

        System.out.println("It is not an abundent 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 ...