This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isPerfectNumber(int number){ | |
if (number<1){ | |
return false; | |
} | |
int accum=0; | |
for (int i=1; i<=(number/2);i++){ | |
if (number%i==0){ | |
accum+=i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void printFactors(int number){ | |
if (number <1){ | |
System.out.println("Invalid Value"); | |
} | |
String factors=""; | |
for (int i = 1;i<=number;i++){ | |
if(number%i==0){ | |
factors+=i+" "; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getGreatestCommonDivisor(int first, int second){ | |
if ((first<10)||(second<10)){ | |
return -1; | |
} | |
int gtDivisor=1; | |
for (int i=2;i<=((first+second)/2);i++) | |
if ((first%i==0)&&(second%i==0)){ | |
gtDivisor=i; | |
} | |
return gtDivisor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean hasSharedDigit(int num1, int num2) { | |
if ((num1 < 10) || (num1 > 99) || | |
(num2 < 10) || (num2 > 99)) { | |
return false; | |
} | |
for (int i = num1; i != 0; i /= 10) { | |
for (int j = num2; j != 0; j /= 10) { | |
if (i%10 == j%10) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getEvenDigitSum(int number){ | |
if (number < 0){ | |
return -1; | |
} | |
int sum=0; | |
for (int i = number; i !=0; i /= 10){ | |
if ((i%10)%2==0){ | |
sum+=i%10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int sumFirstAndLastDigit(int number){ | |
if (number < 0 ) { | |
return -1; | |
} | |
int firstDigit = number%10; | |
int lastDigit=0; | |
for (int i = number; i != 0; i /= 10){ | |
lastDigit = i%10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NumberPalindrome { | |
public static boolean isPalindrome(int number){ | |
if (number < 0){ | |
number = number - (number*2); | |
} | |
String reverseNumber = ""; | |
int newNumber = number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MinutesToYearsDaysCalculator { | |
public static void printYearsAndDays(long minutes){ | |
if (minutes <0) { | |
System.out.println("Invalid Value"); | |
} else { | |
long years = minutes / 525600; | |
long minutesRemaining = (minutes - (years * 525600)); | |
long daysRemaining = minutesRemaining / 1440; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AreaCalculator { | |
public static double area (double radius) { | |
if (radius<0) { | |
return -1.0d; | |
} | |
double areaOfCircle = ((Math.PI * (radius*radius))); | |
return areaOfCircle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TeenNumberChecker { | |
public static boolean hasTeen(int a,int b,int c){ | |
if (a >=13 && a <=19 || | |
b >=13 && b <=19 || | |
c >=13 && c <=19 ) { | |
return true; | |
} | |
return false; |