adspace


Write a program using call by refernce for two different
classes to explain to print whether a given number is
automorphic or not.

Answer Posted / Satyendra Tripathi

Here's an example in Java:nnClass Number:n```npublic class Number {n private int num;nn public void setNumber(int num) {n this.num = num;n }nn public int getNumber() {n return this.num;n }n}nnClass AutomorphicNumber:n```nimport java.util.Scanner;npublic class AutomorphicNumber {n public static void main(String[] args) {n Scanner sc = new Scanner(System.in);n System.out.print("Enter a number: ");n int num = sc.nextInt();n Number n = new Number();n n.setNumber(num);n Automorphic checker = new AutomorphicChecker(n);n checker.checkAutomorphic();n }n}nnClass AutomorphicChecker:n```nimport java.util.Scanner;npublic class AutomorphicChecker {n private Number num;nn public AutomorphicChecker(Number num) {n this.num = num;n }nn public void checkAutomorphic() {n int squareOfNum = (int) Math.pow(num.getNumber(), 2);n if (squareOfNum == num.getNumber() + (int) Math.pow((int) (num.getNumber() - (Math.sqrt(num.getNumber()))), 2)) {n System.out.println("The number is automorphic.");n } else {n System.out.println("The number is not automorphic.");n }n }n}n

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the first argument of the string array in main method?

1031


Are jvm’s platform independent?

983


Can we extract main method from another class?

1035


What is the java api?

999


What do you understand by casting in java language? What are the types of casting?

924


What if I write static public void instead of public static void?

938


What is the locale class?

1027


How does java handle integer overflows and underflows?

1116


What is the resourcebundle class?

1013


what is reflection api? How are they implemented?

1106