Thursday 17 August 2017

Buzz Number

Buzz number:
     A number is said to be Buzz Number if it ends with 7 or is divisible by 7.

Example:
1007 is a Buzz Number as it end with 7.343 is also a Buzz Number as it is divisible by 7 and 77777 is also a Buzz Number as it ends with 7 and also it is divisible by 7.



/* Java program to check given number is buzz number or not*/

package rakesh;
import java.io.*;

class BuzzNumber
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a;
public void show() throws Exception
{
System.out.print("Enter the number:");
a = Integer.parseInt(br.readLine());
if( a % 10 == 7 || a % 7 == 0 )
System.out.println("Entered number is a Buzz number.");
else
System.out.println("Entered number is not a Buzz number.");

}

public static void main(String args[]) throws Exception
{
BuzzNumber bn=new BuzzNumber();
bn.show();
}

}







OUTPUT:


Enter the number:49

Entered number is a Buzz number.


Enter the number:23
Entered number is not a Buzz number.

EVIL NUMBER

EVIL NUMBER:
       In number theory, an evil number is a non-negative number that has an even number of 1s in its binary expansion.
The first evil numbers are:
0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29, 30, 33, 34, 36, 39 .
These numbers give the positions of the zero values in the Thue–Morse sequence.
Numbers that are not evil are called odious numbers.


/* program to check given number is evil number or not*/


import java.io.*;

public class EvilNumber
{
    public static void main(String args[])throws IOException
    {
        int num, a, count , c, i;
        int binNum[] = new int[20];
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter a number:");
        num = Integer.parseInt(br.readLine());
        count = 0;  // count the number of 1's
        c = 0;      // for index of array
        while(num!=0)
        {
            a = num % 2;
            binNum[c] = a;
            if(a == 1)
             count++;
            num = num / 2;
            c++;
        }
        System.out.println("Total number of 1 is = " + count);
        // Print the binary number
        for(i=c-1; i>=0 ; i--)
        {
            System.out.print(binNum[i]+" ");
        }
        // Checking the number is Evil or Not
        if(count % 2 == 0)
        {
            System.out.println("\nEntered number is Evil an Number");
        }
        else
        {
            System.out.println("\nEntered number is not an Evil Number");
        }
    }   
}



OUTPUT:


Enter a number:
10
Total number of 1 is = 2
1 0 1 0 
Entered number is Evil an Number



Enter a number:
13
Total number of 1 is = 3
1 1 0 1 
Entered number is not an Evil Number


DISARIUM NUMBER

DISARIUM NUMBER:
A Disarium number is a number defined by the following process:
Sum of its digits powered with their respective position is equal to the original number.
 
Example:
 175 is a Disarium number:
As 11+32+53 = 135
 
some of disarium numbers
 89, 175, 518 etc.


/*Java program to check given number is disarium number or not*/

 package rakesh;
import java.io.*;
class DisariumNumber
    {
    public static void main(String[] args)throws IOException
        {
            BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
            System.out.print("Enter a number : ");
            int n = Integer.parseInt(br.readLine());
            int copy = n, d = 0, sum = 0;
            String s = Integer.toString(n); //converting the number into a String
            int len = s.length(); //finding the length of the number i.e. no.of digits
           
            while(copy>0)
            {
                d = copy % 10; //extracting the last digit
                sum = sum + (int)Math.pow(d,len);
                len--;
                copy = copy / 10;
            }
           
            if(sum == n)
                System.out.println(n+" is a Disarium Number.");
            else
                System.out.println(n+" is not a Disarium Number.");
        }
    }



OUTPUT:


Enter a number : 135
135 is a Disarium Number.

Enter a number : 321
321 is not a Disarium Number.

MAGIC NUMBER

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.

Example:
199 is a magic number as 1+9+9=19 but 19 is not a single digit number so 1+9=10 and then 1+0=1 which is a single digit number and also 1.Hence it is a magic number.

/*Java program to check given number is magic number or not*/

import java.util.*;
public class MagicNumber
{
 public static void main(String args[])
 {
 Scanner ob=new Scanner(System.in);
 System.out.println("Enter the number:");
 int n=ob.nextInt();
 int sum=0,num=n;
 while(num>9)
 {
 sum=num;int s=0;
 while(sum!=0)
 {
 s=s+(sum%10);
 sum=sum/10;
 }
 num=s;
 }
 if(num==1)
 {
 System.out.println(n+" is a Magic Number.");
 }
 else
 {
 System.out.println(n+" is not a Magic Number.");
 }
 }

}




OUTPUT:


Enter the number:
12

12 is not a Magic Number.


Enter the number:
19
19 is a Magic Number.

AUTOMORPHIC NUMBER

AUTOMORPHIC NUMBER:
An automorphic number is a number whose square ends in the same digits as the number itself.
Examples of automorphic numbers : 5, 6 and 76


/*Java program to find given number is automophic number or not*/


import java.util.*;
class AutomorphicNumber
{
  public static void main(String args[]) throws Exception
  {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a Number : "); // Inputting the number
    int n = sc.nextInt();
    int sq = n*n; // Finding the square

    String num = Integer.toString(n); // Converting the number to String
    String square = Integer.toString(sq); // Converting the square to String

    if(square.endsWith(num)) // If the square ends with the number then it is Automorphic
        System.out.print(n+" is an Automorphic Number.");
    else
        System.out.print(n+" is not an Automorphic Number.");
    }
}





OUTPUT:
Enter a Number : 5
5 is an Automorphic Number.

Enter a Number : 9
9 is not an Automorphic Number.

HARSHAD NUMBER / NIVEN NUMBER

HARSHAD NUMBER (or) NIVEN NUMBER:


In recreational mathematics, a harshad number (or Niven number) in a given number base, is an integer that is divisible by the sum of its digits when written in that base. Harshad numbers in base n are also known as n-harshad (or n-Niven) numbers. Harshad numbers were defined by D. R. Kaprekar, a mathematician from India. The word "harshad" comes from the Sanskrit harį¹£a (joy) + da (give), meaning joy-giver. The term “Niven number” arose from a paper delivered by Ivan M. Niven at a conference on number theory in 1977. All integers between zero and n are n-harshad numbers.


Here some niven numbers are given they are:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100, 102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152, 153, 156, 162, 171, 180, 190, 192, 195, 198, 200, 201, 204
 

Example:
Let’s take the number 126. First, we must find the sum of the digits.
1 + 2 + 6 = 9
Next, we try to divide 126 by 9. And we find…
126 ÷ 9 = 14
There it is. 14 and no remainder; or put another way: 9 is a factor of 126 because
126 = 9 × 14


/*Java program to find given number is Harshad number/ niven number or not*/


import java.util.*;
class HarshadNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
         
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        int c = n, d, sum = 0;
         
        //finding sum of digits
        while(c>0)
        {
            d = c%10;
            sum = sum + d;
            c = c/10;
        }
         
        if(n%sum == 0)
            System.out.println(n+" is a Harshad Number.");
        else
            System.out.println(n+" is not a Harshad Number.");      
    }
}


OUTPUT:
Enter a number : 123
123 is not a Harshad Number

Enter a number : 6
6 is a Harshad Number.

NEON NUMBER

NEON NUMBER:

neon number is a number where the sum of digits of square of the number is equal to the number. For example if the input number is 9, its square is 9*9 = 81 and sum of the digits is 9. i.e. 9 is a neon number.

There are only 3 neon numbers. they are 0,1,9


/*Program for checking given number is neon number or not*/



import java.util.*;
public class NeonNumber
{
    public static void main(String args[])
    {
        Scanner ob=new Scanner(System.in);
        System.out.println("Enter the number to check neon number or not");
        int num=ob.nextInt();
        int square=num*num;
        int sum=0;
        while(square!=0)//Loop to find the sum of digits.
        {
            int a=square%10;
            sum=sum+a;
            square=square/10;
        }
        if(sum==num)
        {
            System.out.println(num+" is a Neon Number.");
        }
        else
        {
            System.out.println(num+" is not a Neon Number.");
        }
    }

}







OUTPUT:

Enter the number to check neon number or not
9

9 is a Neon Number.

Enter the number to check neon number or not
8

8 is not a Neon Number.