0% found this document useful (0 votes)
271 views

Class 11 Computer Project Isc

The document describes a program to check if a number is a fascinating number in Java. A fascinating number is a number where when multiplied by 2 and 3, and those products are concatenated with the original number, all digits from 1 to 9 appear exactly once regardless of zeros. The program accepts a number as input, multiplies it by 2 and 3, concatenates the results with the original number, counts the frequency of each digit, and checks if each digit appears exactly once to determine if the number is fascinating or not.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
271 views

Class 11 Computer Project Isc

The document describes a program to check if a number is a fascinating number in Java. A fascinating number is a number where when multiplied by 2 and 3, and those products are concatenated with the original number, all digits from 1 to 9 appear exactly once regardless of zeros. The program accepts a number as input, multiplies it by 2 and 3, concatenates the results with the original number, counts the frequency of each digit, and checks if each digit appears exactly once to determine if the number is fascinating or not.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 52

Write a Program in Java to input a number and check whether it is a Fascinating

Number or not.

Fascinating Numbers: Some numbers of 3 digits or more exhibit a very


interesting property. The property is such that, when the number is multiplied
by 2 and 3, and both these products are concatenated with the original number,
all digits from 1 to 9 are present exactly once, regardless of the number of
zeroes.

Algorithm:

1. Start the program.

2. Read an integer input from the user.

3. Check if the number is fascinating:

1. Concatenate the number, number multiplied by 2, and number multiplied by


3 into a single number.

2. Count the frequency of each digit in the concatenated number.

3. Iterate through the digit counts from 1 to 9 and check if each digit count is
equal to 1.

4. If any digit count is not equal to 1, return false.

5. If all digit counts are equal to 1, return true.

4. Print "Number is a fascinating number" if step 3 returns true.

5. Print "Number is not a fascinating number" if step 3 returns false.

6. End the program.

import java.util.Scanner;
public class KboatFascinatingNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

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

int num = in.nextInt();

if (num < 100) {

System.out.println(num + " is not a Fascinating Number");

return;

int num2 = num * 2;

int num3 = num * 3;

boolean isFascinating = true;

String str = "" + num + num2 + num3;

for (char i = '1'; i <= '9'; i++) {

int idx1 = str.indexOf(i);

int idx2 = str.lastIndexOf(i);

if (idx1 == -1 || idx1 != idx2) {

isFascinating = false;

break;

}
}

if (isFascinating)

System.out.println(num + " is a Fascinating Number");

else

System.out.println(num + " is not a Fascinating Number");

Write a program in java to accept a number. Check and display whether it is a


Bouncy number or not.

Algorithm:
1. Start the program.

2. Read an integer input from the user.

3. Initialize two boolean variables: `increasing` and `decreasing` to false.

4. Extract the last digit of the number and assign it to the variable `lastDigit`.

5. Remove the last digit from the number.

6. Repeat steps 7-10 until the number is greater than 0:

7. Extract the rightmost digit of the number and assign it to the variable `digit`.

8. Compare `digit` with `lastDigit`:

- If `digit` is greater than `lastDigit`, set `increasing` to true.

- If `digit` is less than `lastDigit`, set `decreasing` to true.

9. Assign the value of `digit` to `lastDigit`.

10. Remove the rightmost digit from the number.

7. If both `increasing` and `decreasing` are true, the number is a bouncy number.

8. If either `increasing` or `decreasing` is true, but not both, the number is not a bouncy
number.

9. Print "The number is a bouncy number" if it is a bouncy number.

10. Print "The number is not a bouncy number" if it is not a bouncy number.

11. End the program.

import java.util.Scanner;

public class KboatBouncyNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

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


int n = in.nextInt();

if (n < 100) {

System.out.println(n + " is not a Bouncy Number.");

return;

int t = n;

boolean isIncreasing = true, isDecreasing = true;

int prev = t % 10;

while (t != 0) {

int d = t % 10;

if (d > prev) {

isIncreasing = false;

break;

prev = d;

t /= 10;

t = n;

prev = t % 10;

while (t != 0) {
int d = t % 10;

if (d < prev) {

isDecreasing = false;

break;

prev = d;

t /= 10;

if (!isIncreasing && !isDecreasing)

System.out.println(n + " is a Bouncy Number.");

else

System.out.println(n + " is not a Bouncy Number.");

}
Write a program in Java to display all the triangular numbers from 3 to n, taking
the value of n as an input.

Algorithm:

1. Start the program.

2. Read an integer input `n`.

3. Print "Triangular numbers from 3 to n:".

4. Initialize a variable `i` with a value of 3.

5. Repeat steps 6-8 until `i` is less than or equal to `n`:

6. Calculate the triangular number using the formula: `(i * (i + 1)) / 2`.

7. Print the calculated triangular number.

8. Increment `i` by 1.

9. End the program.


import java.util.Scanner;

public class KboatTriangularNumbers

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

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

int n = in.nextInt();

if (n < 3) {

System.out.println("Value of n should be greater than or equal to 3");

return;

System.out.println("Triangular Numbers from 3 to "

+ n + ":");

int sum = 3; //First Triangular Number

for (int i = 3; sum <= n; i++) {

System.out.println(sum);

sum += i;

Output
Write a program in Java to enter a number and check whether it is a Smith number or not.

import java.util.Scanner;

public class KboatSmithNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

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

int n = in.nextInt();

if (n <= 0) {

System.out.println(n + " is not a Smith Number.");


return;

boolean isComposite = false;

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

if (n % i == 0) {

isComposite = true;

break;

if (isComposite && n != 1) {

int sumDigits = 0;

int t = n;

while (t != 0) {

int d = t % 10;

sumDigits += d;

t /= 10;

int sumPrimeDigits = 0;

t = n;

for(int i = 2; i < t; i++) {

while(t % i == 0) {

t /= i;
int temp = i;

while (temp != 0) {

int d = temp % 10;

sumPrimeDigits += d;

temp /= 10;

if(t > 2) {

while (t != 0) {

int d = t % 10;

sumPrimeDigits += d;

t /= 10;

if (sumPrimeDigits == sumDigits)

System.out.println(n + " is a Smith Number.");

else

System.out.println(n + " is not a Smith Number.");

else {

System.out.println(n + " is not a Smith Number.");

}
}

A unique-digit integer is a positive integer (without leading zeros) with no duplicates digits. For
example 7, 135, 214 are all unique-digit integers whereas 33, 3121, 300 are not. Given two
positive integers m and n, where m < n, write a program to determine how many unique-digit
integers are there in the range between m and n (both inclusive) and output them. The input
contains two positive integers m and n. Assume m < 30000 and n < 30000. You are to output
the number of unique-digit integers in the specified range along with their values in the format
specified below:

Sample Input:

m = 100

n = 120

Sample Output:

The Unique-Digit integers are:

102, 103, 104, 105, 106, 107, 108, 109, 120.

Frequency of unique-digit integers is : 9


Sample Input:

m = 2500

n = 2550

Sample Output:

The Unique-Digit integers are:

2501, 2503, 2504, 2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2517, 2530,
2519, 2530, 2531, 2534, 2536, 2537, 2538, 2539, 2540, 2541, 2543, 2546, 2547, 2548, 2549.

Frequency of unique-digit integers is: 28.

import java.util.Scanner;

public class KboatUniqueIntegers

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter m: ");

int m = in.nextInt();

if (m < 1 || m > 30000) {

System.out.println("Value of m should be between 1 and 30000");

return;

System.out.print("Enter n: ");

int n = in.nextInt();
if (n < 1 || n > 30000) {

System.out.println("Value of n should be between 1 and 30000");

return;

if (m > n) {

System.out.println("Value of m should be less than n");

return;

System.out.println("The Unique-Digit integers are:");

int count = 0;

for (int i = m; i <= n; i++) {

int num = i;

boolean visited[] = new boolean[10];

boolean isUnique = true;

while (num != 0) {

int d = num % 10;

if (visited[d]) {

isUnique = false;

break;

visited[d] = true;

num /= 10;
}

if (isUnique) {

count++;

System.out.print(i + " ");

System.out.println();

System.out.println("Frequency of unique-digit integers is: " + count);

Accept two positive integers 'm' and 'n', where m is less than n. Display the
number of composite magic integers that are in the range between m and n
(both inclusive) and output them along with frequency, in the format specified
below:

Sample Input:

m=10 n=100

Output: The composite magic numbers are 10,28,46,55,64,82,91,100

Frequency of composite magic numbers: 8

Sample Input:

m=120 n=90

Output: Invalid input

import java.util.Scanner;

public class KboatCompositeMagicNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter m: ");

int m = in.nextInt();

System.out.print("Enter n: ");

int n = in.nextInt();

if (m < 1 || n < 1 || m > n) {


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

return;

System.out.println("The composite magic numbers are:");

int count = 0;

for (int i = m; i <= n; i++) {

boolean isComposite = false;

for (int j = 2; j < i; j++) {

if (i % j == 0) {

isComposite = true;

break;

if (isComposite && i != 1) {

int num = i;

while (num > 9) {

int sum = 0;

while (num != 0) {

int d = num % 10;

num /= 10;
sum += d;

num = sum;

if (num == 1) {

count++;

System.out.print(i + " ");

System.out.println();

System.out.println("Frequency of composite magic numbers: " + count);

}
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all
the odd prime pairs whose sum is equal to the number 'N'.

import java.util.Scanner;

public class GoldbachNumber

public static boolean isPrime(int num) {

int c = 0;

for (int i = 1; i <= num; i++) {

if (num % i == 0) {

c++;
}

return c == 2;

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("ENTER THE VALUE OF N: ");

int n = in.nextInt();

if (n <= 9 || n >= 50) {

System.out.println("INVALID INPUT. NUMBER OUT OF RANGE.");

return;

if (n % 2 != 0) {

System.out.println("INVALID INPUT. NUMBER IS ODD.");

return;

System.out.println("PRIME PAIRS ARE:");


int a = 3;

int b = 0;

while (a <= n / 2) {

b = n - a;

if (isPrime(a) && isPrime(b)) {

System.out.println(a + ", " + b);

a += 2;

}
Write a program to input a number. Use a function int Armstrong(int n) to
accept the number. The function returns 1, if the number is Armstrong,
otherwise zero(0).

import java.util.Scanner;

public class KboatArmstrongNumber

public int armstrong(int n) {

int num = n, cubeSum = 0;

while (num > 0) {

int digit = num % 10;

cubeSum = cubeSum + (digit * digit * digit);

num /= 10;

if (cubeSum == n)

return 1;

else

return 0;
}

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter Number: ");

int num = in.nextInt();

KboatArmstrongNumber obj = new KboatArmstrongNumber();

int r = obj.armstrong(num);

if (r == 1)

System.out.println(num + " is an Armstrong number");

else

System.out.println(num + " is not an Armstrong number");

}
Palindrome Number in Java: Write a program to accept a number from the user
and check whether it is a Palindrome number or not. A number is a Palindrome
which when reads in reverse order is same as in the right order.

import java.util.Scanner;

public class KboatPalindromeNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter the number: ");

int num = in.nextInt();

int copyNum = num;

int revNum = 0;
while(copyNum != 0) {

int digit = copyNum % 10;

copyNum /= 10;

revNum = revNum * 10 + digit;

if (revNum == num)

System.out.println("A Palindrome number");

else

System.out.println("Not a Palindrome number");

Write a program in Java to accept a number. Check and print whether it is a


prime number or not.

A prime number is a number which is divisible by 1 and itself only. For example
2, 3, 5, 7, 11, 13 are all prime numbers.

import java.util.Scanner;

public class KboatPrimeCheck

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

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

int n = in.nextInt();

int c = 0;

for (int i = 1; i <= n; i++) {

if (n % i == 0) {

c++;

if (c == 2) {

System.out.println(n + " is a prime number");

}
else {

System.out.println(n + " is not a prime number");

Write a menu driven program to accept a number from the user and check
whether it is a Prime number or an Automorphic number.

import java.util.Scanner;

public class KboatPrimeAutomorphic

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("1. Prime number");


System.out.println("2. Automorphic number");

System.out.print("Enter your choice: ");

int choice = in.nextInt();

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

int num = in.nextInt();

switch (choice) {

case 1:

int c = 0;

for (int i = 1; i <= num; i++) {

if (num % i == 0) {

c++;

if (c == 2)

System.out.println(num + " is Prime");

else

System.out.println(num + " is not Prime");

break;

case 2:

int numCopy = num;

int sq = num * num;


int d = 0;

/*

* Count the number of

* digits in num

*/

while(num > 0) {

d++;

num /= 10;

/*

* Extract the last d digits

* from square of num

*/

int ld = (int)(sq % Math.pow(10, d));

if (ld == numCopy)

System.out.println(numCopy + " is automorphic");

else

System.out.println(numCopy + " is not automorphic");

break;
default:

System.out.println("Incorrect Choice");

break;

A Prime-Adam integer is a positive integer (without leading zeros) which is a


prime as well as an Adam number.

import java.util.Scanner;

public class PrimeAdam


{

public static int reverse(int num) {

int rev = 0;

while (num != 0) {

int d = num % 10;

rev = rev * 10 + d;

num /= 10;

return rev;

public static boolean isAdam(int num) {

int sqNum = num * num;

int revNum = reverse(num);

int sqRevNum = revNum * revNum;

int rev = reverse(sqNum);

return rev == sqRevNum;

public static boolean isPrime(int num) {


int c = 0;

for (int i = 1; i <= num; i++) {

if (num % i == 0) {

c++;

return c == 2;

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter the value of m: ");

int m = in.nextInt();

System.out.print("Enter the value of n: ");

int n = in.nextInt();

int count = 0;

if (m >= n) {

System.out.println("INVALID INPUT");

return;

}
System.out.println("THE PRIME-ADAM INTEGERS ARE:");

for (int i = m; i <= n; i++) {

boolean adam = isAdam(i);

if (adam) {

boolean prime = isPrime(i);

if (prime) {

System.out.print(i + " ");

count++;

if (count == 0) {

System.out.print("NIL");

System.out.println();

System.out.println("FREQUENCY OF PRIME-ADAM INTEGERS IS: " +


count);

}
Write a program to input a number and check and print whether it is a Pronic
number or not. [Pronic number is the number which is the product of two
consecutive integers.]

Examples:

12 = 3 * 4

20 = 4 * 5

42 = 6 * 7

import java.util.Scanner;

public class KboatPronicNumber

public void pronicCheck() {

Scanner in = new Scanner(System.in);


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

int num = in.nextInt();

boolean isPronic = false;

for (int i = 1; i <= num - 1; i++) {

if (i * (i + 1) == num) {

isPronic = true;

break;

if (isPronic)

System.out.println(num + " is a pronic number");

else

System.out.println(num + " is not a pronic number");

}
An Abundant number is a number for which the sum of its proper factors is
greater than the number itself. Write a program to input a number and check
and print whether it is an Abundant number or not.

import java.util.Scanner;

public class KboatAbundantNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter the number: ");

int n = in.nextInt();
int sum = 0;

for (int i = 1; i < n; i++) {

if (n % i == 0)

sum += i;

if (sum > n)

System.out.println(n + " is an abundant number");

else

System.out.println(n + " is not an abundant number");

}
Write a program to input a number. Check and display whether it is a Niven
number or not. (A number is said to be Niven which is divisible by the sum of its
digits).

import java.util.Scanner;

public class KboatNivenNumber

public void checkNiven() {

Scanner in = new Scanner(System.in);

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

int num = in.nextInt();

int orgNum = num;

int digitSum = 0;

while (num != 0) {

int digit = num % 10;

num /= 10;

digitSum += digit;

/*

* digitSum != 0 check prevents

* division by zero error for the


* case when users gives the number

* 0 as input

*/

if (digitSum != 0 && orgNum % digitSum == 0)

System.out.println(orgNum + " is a Niven number");

else

System.out.println(orgNum + " is not a Niven number");

Write a program to accept a number and check whether it is a 'Spy Number' or


not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: Sample Input: 1124

Sum of the digits = 1 + 1 + 2 + 4 = 8

Product of the digits = 1*1*2*4 = 8

import java.util.Scanner;

public class KboatSpyNumber

public void spyNumCheck() {

Scanner in = new Scanner(System.in);

System.out.print("Enter Number: ");

int num = in.nextInt();

int digit, sum = 0;

int orgNum = num;

int prod = 1;

while (num > 0) {

digit = num % 10;

sum += digit;

prod *= digit;
num /= 10;

if (sum == prod)

System.out.println(orgNum + " is Spy Number");

else

System.out.println(orgNum + " is not Spy Number");

A special two-digit number is such that when the sum of its digits is added to
the product of its digits, the result is equal to the original two-digit number
import java.util.Scanner;

public class KboatSpecialNumber

public void checkNumber() {

Scanner in = new Scanner(System.in);

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

int orgNum = in.nextInt();

int num = orgNum;

int count = 0, digitSum = 0, digitProduct = 1;

while (num != 0) {

int digit = num % 10;

num /= 10;

digitSum += digit;

digitProduct *= digit;

count++;

}
if (count != 2)

System.out.println("Invalid input, please enter a 2-digit number");

else if ((digitSum + digitProduct) == orgNum)

System.out.println("Special 2-digit number");

else

System.out.println("Not a special 2-digit number");

Output
A prime number is said to be 'Twisted Prime', if the new number obtained after
reversing the digits is also a prime number. Write a program to accept a number
and check whether the number is 'Twisted Prime' or not.

import java.util.Scanner;

public class KboatTwistedPrime

public void twistedPrimeCheck() {

Scanner in = new Scanner(System.in);

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

int num = in.nextInt();

if (num == 1) {

System.out.println(num + " is not a twisted prime number");

else {

boolean isPrime = true;

for (int i = 2; i <= num / 2; i++) {

if (num % i == 0) {

isPrime = false;

break;

}
}

if (isPrime) {

int t = num;

int revNum = 0;

while (t != 0) {

int digit = t % 10;

t /= 10;

revNum = revNum * 10 + digit;

for (int i = 2; i <= revNum / 2; i++) {

if (revNum % i == 0) {

isPrime = false;

break;

if (isPrime)
System.out.println(num + " is a twisted prime number");

else

System.out.println(num + " is not a twisted prime number");

Write a program to enter two numbers and check whether they are co-prime or
not.
import java.util.Scanner;

public class KboatCoprime

public void checkCoprime() {

Scanner in = new Scanner(System.in);

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

int a = in.nextInt();

System.out.print("Enter b: ");

int b = in.nextInt();

int hcf = 1;

for (int i = 1; i <= a && i <= b; i++) {

if (a % i == 0 && b % i == 0)

hcf = i;

if (hcf == 1)

System.out.println(a + " and " + b + " are co-prime");

else
System.out.println(a + " and " + b + " are not co-prime");

A number is said to be Duck if the digit zero is (0) present in it. Write a program
to accept a number and check whether the number is Duck or not. The program
displays the message accordingly. (The number must not begin with zero)

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class KboatDuckNumber

public void duckNumberCheck() throws IOException {


InputStreamReader reader = new InputStreamReader(System.in);

BufferedReader in = new BufferedReader(reader);

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

boolean isDuck = false;

boolean firstZero = false;

int c = 0, d;

/*

* 10 is the ASCII code of newline

* We will read from inputstream

* one character at a time till we

* encounter a newline i.e. enter

*/

while((d = in.read()) != 10) {

char ch = (char)d;

if (c == 0 && ch == '0' )

firstZero = true;

if (!firstZero && ch == '0')

isDuck = true;
c++;

if (isDuck)

System.out.println("Duck Number");

else

System.out.println("Not a Duck Number");

Write a program to display all the 'Buzz Numbers' between p and q (where p<q).
A 'Buzz Number' is the number which ends with 7 or is divisible by 7.
import java.util.Scanner;

public class KboatBuzzNumber

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter p: ");

int p = in.nextInt();

System.out.print("Enter q: ");

int q = in.nextInt();

if (p < q) {

System.out.println("Buzz Numbers between "

+ p + " and " + q);

for (int i = p; i <= q; i++) {

if (i % 10 == 7 || i % 7 == 0)

System.out.println(i);

else {

System.out.println("Invalid Inputs!!!");

System.out.println("p should be less than q");

}
}

You might also like