Untitled
unknown
plain_text
a year ago
2.0 kB
3
Indexable
Never
import java.util.Scanner; class IntegerProperty{ IntegerProperty(int a){ int num = a; } boolean isPrime(){ for(int i = 2;i<num;i++){ if (num%i == 0){ return false; } else { return true; } } } boolean isAmstrong(){ int sum = 0,b,temp=num; while(temp>0){ b = temp%10; sum += b*b*b; temp = int(temp/10); } if (num == sum){ return true; } else { return false; } } boolean isStrong(){ int sum = 0,temp=num,b; while(temp>0){ b=temp%10; sum+= factorial(b); temp = int(temp/10); } if(num == sum){ return true; } else { return false; } } int factorial(int a){ if (a == 0){ return 1; } else if (a == 1){ return 1; } else { return a * factorial(a-1); } } } public class Main{ public static void main(String []args){ Scanner input = new Scanner(System.in); int number = input.nextInt(); IntegerProperty obj = new IntegerProperty(number); boolean prime = obj.isPrime(); boolean amstrong = obj.isAmstrong(); boolean strong = obj,isStrong(); if(prime == true){ System.out.printf("%d is a prime number.",number); } else { System.out.printf("%d is not a prime number.",number); } if(amstrong == true){ System.out.printf("%d is a strong number.",number); } else { System.out.printf("%d is not a strong number.",number); } if(strong == true){ System.out.printf("%d is an Armstrong number.",number); } else { System.out.printf("%d is not an Armstrong number.",number); } } }