AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Cozy number

Find the given number N is cozy number or not. Input Constrains: 1<=N<=30000 Note: If input is not according to the constrains then output should be InputValueOutOfBoundryException Input 1: 6 output 1: 6 is a cozy number. Input 2: 210 output 2: 210 is not a cozy number. Input: -1 output: InputValueOutOfBoundryException Explanation: The proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110. Summation of all the divisor of 220 is 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; Now Summation of all the divisor of 284 is 220 therefore 220 is cozy number.


corejava x 353
programming x 168
Posted On : 2016-10-21 00:20:17.0
profile Aarti Kumar - anyforum.in Aarti Kumar
5900
up-rate
5
down-rate

Answers


import java.util.Scanner;

public class CozyNumber {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int number=input.nextInt();
if(number>=1 && number<=30000){
System.out.print(number);
System.out.print(number==getSumDivisors(getSumDivisors(number)) || number==1?" is a ":" is not a ");
System.out.print("cozy number");
}else{
System.out.println("InputValueOutOfBoundryException");
}
}

public static int getSumDivisors(int num){
int sum=0;
for(int i=1;i<num;i++){
if(num%i==0){
sum=sum+i;
}
}
return sum;
}
}

Posted On : 2016-10-21 23:08:35
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222642
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in