COMP_PROJECT_11_(1)[1]
COMP_PROJECT_11_(1)[1]
COMP_PROJECT_11_(1)[1]
Class: XI-G
2024-25
Internal Examiner’s
sign: __________
External Examiner’s
sign: __________
Acknowledgement
I would like to express my special thanks of
gratitude to my teacher Akash Sir as well as our
Senior Principal Mrs. Jyoti Kashyap and
Principal Shivani Singh who gave me the golden
opportunity to do this wonderful project on the
topic (Java Programs), which also helped me in
doing a lot of Research and i came to know
about so many new things I am really thankful
to them.
import java.util.*;
class PrimoNumberChecker {
boolean isPrimeDigit(int digit) {
return digit == 2 || digit == 3 || digit == 5 || digit == 7;
}
boolean isPrimoNumber(int number) {
if (number < 1000) {
return false;
}
while (number > 0) {
int digit = number % 10;
if (!isPrimeDigit(digit)) {
return false;
}
number /= 10;
}
return true;
}
public static void main() {
Scanner sc = new Scanner(System.in);
import java.util.*;
class MatrixOperations {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the square matrix (M > 3 and M < 10): ");
int M = sc.nextInt();
if (M <= 3 || M >= 10) {
System.out.println("Invalid input. Please enter a value between 4 and 9.");
return;
}
int[][] matrix = new int[M][M];
System.out.println("Enter the elements of the matrix:");
for (int i = 0; i < M; i++) {
for (int j = 0; j < M; j++) {
matrix[i][j] = sc.nextInt();
}
}
// Extract non-boundary elements and sort them using bubble sort
int nonBoundaryCount = (M - 2) * (M - 2);
for (int i = 1; i < M - 1; i++) {
for (int j = 1; j < M - 1; j++) {
for (int k = 1; k < M - 1; k++) {
for (int l = 1; l < M - 1; l++) {
if (matrix[i][j] > matrix[k][l]) {
int temp = matrix[i][j];
matrix[i][j] = matrix[k][l];
matrix[k][l] = temp;
}
}
}
}
}
System.out.println("\nREARRANGED MATRIX");
printMatrix(matrix);
System.out.println("\nDIAGONAL ELEMENTS");
for (int i = 0; i < M; i++) {
System.out.print(matrix[i][i] + "");
}
System.out.println();
for (int i = 0; i < M; i++) {
System.out.print(matrix[i][M - i - 1] + "");
}
System.out.println();
Input:
Read the size M of the square matrix.
Read the elements of the matrix.
Extract and Sort Non-Boundary Elements:
Iterate over the matrix, excluding the boundary elements.
For each non-boundary element:
Compare it with all other non-boundary elements.
If a smaller element is found, swap them.
Calculate Diagonal Sums:
Initialize two variables to store the sums of the two diagonals.
Iterate over the matrix:
Add the element at the current index to the first diagonal sum.
Add the element at the opposite diagonal index to the second diagonal sum.
Print Matrices:
Print the original matrix.
Question 3
Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only.
The words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
1. Find the number of words beginning and ending with a vowel.
2. Place the words which begin and end with a vowel at the beginning, followed by the
remaining words as they occur in the sentence.
Test your program with the sample data and some random data:
import java.util.*;
class SentenceRearrangement {
boolean isVowel(char ch) {
return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
}
public static void main() {
Scanner sc = new Scanner(System.in);
Algorithm:
import java.util.*;
class SmallestNumberDigitSum {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter M: ");
int M = sc.nextInt();
System.out.print("Enter N: ");
int N = sc.nextInt(); 1
int num = M + 1;
while (true) {
int sum = 0;
int temp = num;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
}
if (sum == N) {
int digitCount = (int) Math.log10(num) + 1;
System.out.println("The required number = " + num);
System.out.println("Total number of digits = " + digitCount);
break;
}
num++;
}
}
}
Algorithm:
Input:
Read two positive integers M and N from the user.
Validate Input:
Check if M is between 100 and 10000 and N is between 1 and 99.
Initialize:
Set num to M + 1.
Iterate and Check:
Repeat the following steps until a suitable number is found:
Calculate the sum of digits of num.
If the sum is equal to N, break the loop.
Increment num.
Output:
If a suitable number is found, print the number and its digit count.
Otherwise, print "Invalid Input".
Question 5
A composite Magic number is a positive integer which is composite as well
as a magic number.
Composite number: A composite number is a number which has more
than two factors. For example: 10 Factors are: 1,2,5,10
Magic number: A Magic number is a number in which the eventual sum of
the digit d is equal to 1. For example: 28 = 2+8=10= 1+0=1
Accept two positive integers m and n, where m is less than n as user input.
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:
import java.util.*;
class CompositeMagicNumbers {
Algorithm
The is composite function checks if a number is composite by iterating from 2
to its square root.
The is magic function repeatedly sums the digits of a number until it reaches a
single-digit number. If this final digit is 1, the number is magic.
The main function reads the input, validates it, and iterates through the range
m to n. For each number, it checks if it's composite and magic, and if so, prints
it and increments the count.
Finally, the total count of composite magic numbers is printed.
Question 6
An ISBN ( International Standard Book Number) is a ten digit code which
uniquely identifies a book. The first nine digits represent the Group,
Publisher and Title of the book and the last digit is used to check whether
ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 and 9.
Sometimes it is necessary to make the last digit equal to ten; this is done
by writing the last digit of the code as X. To verify an ISBN, calculate 10
times the first digit, plus 9 times the second digit, plus 8 times the third
and so on until we add 1 time the last digit. If the final number leaves no
remainder when divided by 11, the code is a valid ISBN.
class ISBN
{
public static void main(String nm)
{
int ln=nm.length();
if(ln<10 || ln>10) System.out.println("INVALID INPUT");
else
{
int tot=0;
int p=10;
int d;
for(int i=0; i<10; i++)
{
char ch=nm.charAt(i);
if(ch=='X') d=10;
else d=ch-48;
tot = tot + d*p--;
}
if(tot%11==0) System.out.println(nm + "= it is an ISBN number ");
else System.out.println(nm + " = it is NOT an ISBN number ");
} } }
Question 7
Write a program to declare a square matrix A[][] of order (M X M) where 'M' is the
number of rows and the number of columns such that M must be greater than 2 and less
than 20. Allow the user to input integers into this matrix. Display appropriate error
message for an invalid input. Perform the following tasks:
1. Display the input matrix.
2. Create a mirror image of the inputted matrix.
3. Display the mirror image matrix.
Test your program for the following data and some random data:
import java.util.*;
class MirrorMatrix {
public static void main() {
Scanner sc = new Scanner(System.in);
import java.util.*;
class PalindromeWords {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a sentence: ");
String sentence = sc.nextLine();
String[] words = sentence.split("\\s+");
int count = 0;
System.out.println("Palindrome words:");
for (String word : words) {
if (isPalindrome(word)) {
System.out.print(word + " ");
count++;
}
}
System.out.println("\nNumber of palindromic words: " + count);
}
boolean isPalindrome(String word) {
int left = 0, right = word.length() - 1;
while (left < right) {
if (word.charAt(left) != word.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}}
Algorithm:
Initialize pointers:
Initialize two pointers, left and right, to the beginning and end of the word,
respectively.
Iterate and compare:
While left is less than right:
If the characters at left and right are different, the word is not a palindrome.
Move left one position to the right and right one position to the left.
Return result:
If the loop completes without finding a mismatch, the word is a palindrome.
Return true.
Otherwise, return false.
Question 9
A prime palindrome integer is a positive integer (without leading zeros) which is prime as
well as a palindrome. Given two positive integers m and n, where m < n, write a program
to determine how many prime-palindrome integers are there in the range between m and
n (both inclusive) and output them.
The input contains two positive integers m and n where m < 3000 and n < 3000. Display
the number of prime palindrome integers in the specified range along with their values in
the format specified below:
Test your program with the sample data and some random data:
import java.util.*;
class PrimePalindrome {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the values of m and n: ");
int m = sc.nextInt();
int n = sc.nextInt();
if (n > 3000) {
System.out.println("OUT OF RANGE");
return;
}
return true;
}
}
Algorithm:
Input:
Read two positive integers m and n from the user.
Validate Input:
Check if n is greater than 3000. If so, print an error message and exit.
Iterate and Check:
For each number i from m to n:
Check if i is a prime palindrome using the isPrimePalindrome function.
If i is a prime palindrome, print it and increment a counter.
Output:
Print the list of prime palindrome numbers.
Print the total count of prime palindrome numbers.
isPrimePalindrome function:
import java.util.*;
class NumberToWords {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a natural number less than 1000: ");
int number = sc.nextInt();
import java.util.*;
class DateValidation {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your date of birth in dd mm yyyy format: ");
int day = sc.nextInt();
int month = sc.nextInt();
int year = sc.nextInt();
return true;
}
import java.util. *;
class DenominationBreakdown {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the amount: ");
int amount = sc.nextInt(); 1
if (amount <= 0) {
System.out.println("Invalid amount");
return;
}
// Convert amount to words
String[] words = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
"SEVEN", "EIGHT", "NINE"};
String amountInWords = "";
for (char digit : String.valueOf(amount).toCharArray()) {
amountInWords += words[digit - '0'] + "";
}
System.out.println(amountInWords.trim().toUpperCase());
// Denomination breakdown
int[] denominations = {1000, 500, 100, 50, 20, 10, 5, 2, 1};
System.out.println("DENOMINATION:");
for (int denomination : denominations) {
int count = amount / denomination;
if (count > 0) {
System.out.println(denomination + " X " + count + " = " +
(denomination * count));
amount %= denomination; } } }
}
Algorithm:
import java.util.*;
class KaprekarNumbers {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter p: ");
int p = sc.nextInt();
System.out.print("Enter q: ");
int q = sc.nextInt();
System.out.println("THE KAPREKAR NUMBERS ARE:");
int count = 0;
for (int i = p; i <= q; i++) {
if (isKaprekar(i)) {
System.out.print(i + "");
count++;
}
}
System.out.println("\nFREQUENCY OF KAPREKAR NUMBERS IS: " + count);
}
boolean isKaprekar(int n) {
if (n == 1) {
return true;
}
int sqr = n * n;
int digits = (int) Math.log10(n) + 1;
int divisor = (int) Math.pow(10, digits);
int rightPart = sqr % divisor;
int leftPart = sqr / divisor;
return leftPart + rightPart == n;
} }
Algorithm:
Input:
Read two positive integers p and q from the user.
Iterate and Check:
For each number n from p to q:
Calculate the square of n.
Determine the number of digits in the square (digits).
Calculate the divisor divisor as 10 raised to the power of digits.
Calculate the right part of the square: rightPart = sqr % divisor.
Calculate the left part of the square: leftPart = sqr / divisor.
If leftPart + rightPart == n, then n is a Kaprekar number.
If n is a Kaprekar number, print it and increment a count variable.
Output:
Print the list of Kaprekar numbers found.
Print the total count of Kaprekar numbers.
Question 14
Input a paragraph containing 'n' number of sentences where (1<=n<=4).
The words are to be separated with single blank space and are in upper
case. A sentence may be terminated either with a full stop (.) or question
mark (?).
Perform the following:
1. Enter the number of sentences, if it exceeds the limit show a message.
2. Find the number of words in the paragraph
3. Display the words in ascending order with frequency.
import java.util.Arrays;
import java.util.*;
public class WordFrequency {
public static void main() {
Scanner sc = new Scanner(System.in);
Algorithm:
class Prime {
int n;
Prime(int n) {
this.n = n;
}
void print() {
System.out.println("Number: " + n);
System.out.println("Nearest prime number greater than " + n + ": " +
nextPrime());
}
int nextPrime() {
int num = n + 1;
while (!isPrime(num)) {
num++;
}
return num;
}
int i = 5;
while (i * i <= num) {
if (num % i == 0 || num % (i + 2) == 0) {
return false;
}
i += 6;
}
return true;
}