AUXILIAM NUMBER Write a program to create a class named Auxilium with the following properties: - Instance variables/data members: int n to store the number using scanner class to count the factors of a number boolean a to store true if number is prime int sum to find the sum of the prime numbers intc Member methods: Auxilium() default constructor to initialize data members void input() method to input a number using scanner class boolean prime() method that checks if the original number as well as others are prime numbers or not. For e.g. Original number = 41 is a prime number void check() method to print the output - “Auxilium Number" if the combination of all the consecutive prime numbers up to the original number when added gives rise to the same number. For e.g. Original number = 41 Combination = 2 + 3 + 5 + 7 + 11 + 13 = 41 Result = Auxilium Number For any other prime number not producing desired result, the program prints the message- “Not an Auxilium Number” and if the user inputs any composite number then the program prints - "Sorry! Not Possible!”. Write a main method to create the object of the class and call the above methods.

 4) Write a program to create a class named Auxilium with the following properties: -

Instance variables/data members:

int n

to store the number using scanner class

to count the factors of a number

boolean a

to store true if number is prime

int sum

to find the sum of the prime numbers

intc

Member methods:

Auxilium()

default constructor to initialize data members

void input()

method to input a number using scanner class

boolean prime() method that checks if the original number as well as others are

prime numbers or not. For e.g. Original number = 41 is a prime number

void check()

method to print the output - “Auxilium Number" if

the combination of all the consecutive prime numbers up to the

original number when added gives rise to the same number.

For e.g.

Original number = 41

Combination = 2 + 3 + 5 + 7 + 11 + 13

= 41

Result

= Auxilium Number

For any other prime number not producing desired result, the program prints the message-

“Not an Auxilium Number” and if the user inputs any composite number then the program

prints - "Sorry! Not Possible!”.

Write a main method to create the object of the class and call the above methods.



PROGRAM CONTRIBUTED BY ANUBRATA DAS

import java.util.Scanner;
class Auxilium
{
    int n;
    int c;
    boolean a;
    int sum;
    Auxilium() {
        c=sum=0;
        a=false;
    }

    void input() {
        System.out.println("ENTER A NUMBER");
        n=new Scanner(System.in).nextInt();
    }

    boolean prime() {
        for(int i=1;i<=n;++i) {
            if(n%i==0)
                ++c;
        }
        a = c==2? true:false;
        System.out.println(c==2? "ORIGINAL NUMBER = "+n+" IS A PRIME NUMBER" : "SORRY! NOT POSSIBLE!");
        return a;
    }

    void check() {
        int d=0;
        if(a) {
            for(int i=2;i<=n;++i) {
                d=0;
                for(int j=1;j<=i;++j) {
                    if(i%j==0)
                        ++d;
                }
                sum+=d==2? i:0; 
                if(sum==n) {
                    System.out.println(n+" IS AN AUXILIUM NUMBER");
                    break;
                }
            }
            if(sum!=n)
                System.out.println(n+" IS NOT AN AUXILIUM NUMBER");
        }
    }

    static void main(String [] args) {
        Auxilium ob = new Auxilium();
        ob.input();
        ob.prime();
        ob.check();
    }
}

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close