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
What is the first argument of the string array in main method?
Are jvm’s platform independent?
Can we extract main method from another class?
What is the java api?
What do you understand by casting in java language? What are the types of casting?
What if I write static public void instead of public static void?
What is the locale class?
How does java handle integer overflows and underflows?
What is the resourcebundle class?
what is reflection api? How are they implemented?