For loop


1.       Write a Program in Java to input a number and check whether it is a Pronic Number or Heteromecic Number or not.
       2, 6, 12, 20, 30, 42, 56, 72, 90
import java.util.*;
class PronicNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);   
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        int flag = 0;
        for(int i=0; i<n; i++)
        {
            if(i*(i+1) == n)
            {
                flag = 1;
                break;
            }
        }
        
        if(flag == 1)
            System.out.println(n+" is a Pronic Number.");
        else
            System.out.println(n+" is not a Pronic Number.");     
    }
}
Output : Enter a number : 7
  73 is not a Pronic Number.









No comments:

Post a Comment

what is chain constructor in java

  In Java, chain constructor refers to a technique where one constructor calls another constructor within the same class. This is achieved b...