You are on page 1of 11

COMPUTER

PROJECT

NAME – AYUSH VARDHAN


CLASS - XII A4
UID -
INDEX
Question-1) An Evil number is a positive whole number which has even number of 1's in its binary
equivalent. Example: Binary equivalent of 9 is 1001, which contains even number of 1's. A few evil
numbers are 3, 5, 6, 9…. Design a program to accept a positive whole number and find the binary
equivalent of the number and count the number of 1's in it and display whether it is a Evil number or not
with an appropriate message. Output the result in format given below:

Example 1
Input: 15
Binary Equivalent: 1111
No. of 1's: 4
Output: Evil Number

Solution:

import java.util.Scanner;

public class EvilNumber

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.print("Enter a positive number: ");

int n = in.nextInt();

if (n < 0)

System.out.println("Invalid Input");

return;

int count = 0;

int p = 0;

int binNum = 0;

while (n > 0)

int d = n % 2;

if (d == 1)
count++;

binNum += (int)(d * Math.pow(10, p));

p++;

n /= 2;

System.out.println("Binary Equivalent: " + binNum);

System.out.println("No. of 1's: " + count);

if (count % 2 == 0)

System.out.println("Output: Evil Number");

else

System.out.println("Output: Not an Evil Number");

OUTPUT
Question-2)Write a program to check whether the number is a Magic number or not

Magic number: A Magic number is a number in which the eventual sum of the digit is equal to 1.
For example: 28 = 2+8=10= 1+0=1

Solution:

import java.util.Scanner;

public class MagicNumber

public static void main(String args[])

int n, remainder = 1, number, sum = 0;

Scanner sc = new Scanner(System.in);

System.out.print("Enter a number you want to check: ");

n = sc.nextInt();

number = n;

while (number > 9)

while (number > 0)

remainder = number % 10;

sum = sum + remainder;

number = number / 10;

number = sum;

sum = 0;

if (number == 1)

{
System.out.println("The given number is a magic number.");

else

System.out.println("The given number is not a magic number.");

OUTPUT
Question-3) Write a program to check whether the number is a Keith Number or Not .

Solution:
import java.util.*;

public class Main

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

int inputNumber = sc.nextInt();

System.out.println("Given number: "+inputNumber);

int temporaryNumber = inputNumber;

String str = Integer.toString(inputNumber);

int len =str.length();

int store[]=new int[inputNumber];

int i, sum;

for(i=len-1; i>=0; i--)

store[i]=temporaryNumber % 10;

temporaryNumber = temporaryNumber/10;

i=len; sum=0;

while(sum<inputNumber)
{

sum = 0;

for(int j=1; j<=len; j++)

sum=sum+store[i-j];

store[i]=sum;

i++;

if(sum==inputNumber)

System.out.println(inputNumber + " is a Keith Number.");

else

System.out.println(inputNumber + " is not a Keith Number.");

OUTPUT
Question-4)Write a program to check whether the Number is a Emirp or not .

A number is called an emirp number if we get another prime number on reversing the number itself. In
other words, an emirp number is a number that is prime forwards or backward. It is also known
as twisted prime numbers.

SOLUTION:
import java.util.*;

public class EmirpNumber

public static boolean isPrime(int n)

if (n <= 1)

return false;

for (int i = 2; i < n; i++)

if (n % i == 0)

return false;

return true;

public static boolean isEmirp(int n)

if (isPrime(n) == false)

return false;

int reverse = 0;

while (n != 0)

int digit = n % 10;

reverse = reverse * 10 + digit;

n = n/10;

return isPrime(reverse);
}

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number to check: ");

int n=sc.nextInt();

if (isEmirp(n) == true)

System.out.println("Yes, the given number is an emirp number.");

else

System.out.println("No, the given number is not an emirp number.");

OUTPUT
Question-5)

You might also like