Posts

Showing posts from 2021

Weird Number

Image
Weird Number in Java Question :   Write a program to accept a number and check whether it is  Weird  number or not. Weird Number  :  A Weird number is a natural number that is Abundant but not Semi-Perfect . In other words, the sum of the proper divisors (divisors including 1 but not itself) of the number is greater than the number, but no subset of those divisors sums to the number itself.  First few Weird Numbers : 70, 836, 4030, 5830, 7192, 7912, 9272, 10430, 10570, 10792, 10990, 11410, 11690 Abundant Number : A number ‘n’ is said to be Abundant Number if sum of all the proper divisors of the number is greater than the number ‘n’. Semi-Perfect Number : A Semi-Perfect number or Pseudo-Perfect number is a natural number n that is equal to the sum of all or some of its proper divisors. 

Semi Perfect/Pseudo Perfect Number

Image
Semi Perfect/Pseudo Perfect Number in JAVA Question :   Write a program to accept a number and check whether it is  Semi-Perfect number or not. Semi-Perfect Number  :  A Semi-Perfect number or Pseudo-Perfect number is a natural number n that is equal to the sum of all or some of its proper divisors.  A Semi-Perfect number that is equal to the sum of all its proper divisors is a perfect number. First few Semi-Perfect numbers are: 6, 12, 18, 20, 24, 28, 30, 36, 40 etc. Proper Divisors : Proper divisor is a positive divisor of a number, excluding itself. Example  :- Input : 6 Proper Divisors of 6 : 1, 2, 3 Sum of Proper Divisors : 1 + 2 + 3 = 6 Output : Semi-Perfect Number (Since sum of all the factors is equal to the number, it is also a Perfect Number). Input : 12 Proper Divisors of 12 : 1, 2, 3, 4, 6 Sum of Proper Divisors : 1 + 2 + 3 + 6 = 12 Output : Semi-Perfect Number

Ugly Number in Java

Image
 Ugly Number Question :   Write a program to accept a number and check whether it is Ugly number or not. Ugly Number : An Ugly number is a positive integer whose prime factors are limited to 2, 3, and 5 First 11 Ugly Numbers : 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15 Example :- Factors of 12 : 1, 2, 3, 4, 6, 12 Prime Factors of 12 : 2, 3 Prime Factorization : Writing a number as products of its prime factors. 12 : 2 X 2 X 3 = 12 

Magic Composite Number in Java

Image
  Magic Composite Number Question :   Write a program to accept a number and check whether it is a Magic Composite Number or not. Magic Composite Number : A Magic Composite Number is a positive integer which is composite as well as a magic number. First 6 Magic Composite Numbers : 10, 28, 46, 55, 64, 82 Magic Number : A Number is said to be a Magic Number if the sum of its digits are calculated till a single digit is obtained by recursively adding the sum of its digits. If the single digit comes to be 1 then the number is a Magic Number. 199 = 1 + 9 + 9 = 19     19 = 1 + 9 = 10     10 = 1 + 0 = 1  Composite  Number : A composite number is a number that has more than two factors.

Bell Number Triangle Pattern

Image
Bell Number Triangle Pattern in Java Question :   Write a program to print the following pattern. Bell Number Triangle Pattern

Pattern Program using 2D Array in JAVA

Image
Pattern Program #2 using Array in Java Question :   Write a program to print the following pattern.

Interesting Pattern Program using Array in JAVA

Image
Pattern Program using Array in Java Question :   Write a program to print the following pattern.  

Frequency of each digit of a number in Java

Image
Frequency of each digit of a Number Question :   Write a program to count and display the frequency of each digit of a number. For Example  :-   Input                                                            : 19224 Output                                                      :   Frequency of 1 is : 1                                                                        Frequency of 2 is : 2          ...

Convert Time into Words in JAVA

Image
Time Program in Java Question :   Given a time in the format of hh:mm (12-hour format) 0 < hh <=12, 0 <= mm < 60. The task is to convert it into words as shown: For Example  :-   Input                                                           : hr = 5, min = 0 Output                                                     : Five O' Clock   Input                                                           : hr = 6, min = 24 Output        ...

Smith Number in JAVA

Image
Smith Number in JAVA Smith Number : A Smith Number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of Prime Factorization (excluding 1).   The first few Smith Numbers are : 4, 22, 27, 58, 85, 94, 121........ Etc. For Example :-   Input                                                            : 22 Sum of digits                                         : 2 + 2 = 4 Sum of digits of Prime Factors  : 2 + 2 = 4 Output                                          ...

Swap two Strings without using third variable

Image
Swapping of two Strings without using third variable in Java Swapping : Swapping simple means "Exchange". Swapping the values of two variables means exchanging the value of two variable with each other. For Example :- Input :- str1 = "Java" str2 = "Code"   Output after swapping :- str1 = "Code" str2 = "Java"

PigLatin Word in JAVA

Image
PigLatin Word in JAVA PigLatin Word : A Pig Latin word is obtained by framing a new word starting with the first vowel present in the word. The remaining letters before the first vowel will be added in the last followed by ' ay '. For Example :- Input           : "trouble" Output      : "oubletray"   Input           : "bluejcode" Output      : "uejcodeblay"

Kaprekar Number in JAVA

Image
Kaprekar Number in JAVA Kaprekar Number : A Kaprekar Number is a number whose square when divided into two parts and such that sum of parts is equal to the original number and none of the parts has value 0. Consider an n-digit number k . Square it and add the right n digits of the square to the left n or n-1 digits. If the resultant sum is equal to the number k, then k is called a Kaprekar Number. For Example :- Input           : 9 Square       : 81 Sum           : 8 + 1 = 9 Output      : It is a Kaprekar Number     Input           : 297 Square       : 88209 Sum           : 88 + 209 = 297 Output      : It is a Kaprekar Number  Input           : 10 Square       : 100 Sum ...