0% found this document useful (0 votes)
10 views99 pages

Java Programs for Class 10 Computer Project

This document is a computer project by Subhrajit Halder, a Class 10 student, detailing various Java programs. It includes code for sorting arrays, finding the second largest element, checking Armstrong numbers, printing patterns, and more, along with explanations and variable distribution tables. The project acknowledges the support of teachers, parents, and friends in its completion.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views99 pages

Java Programs for Class 10 Computer Project

This document is a computer project by Subhrajit Halder, a Class 10 student, detailing various Java programs. It includes code for sorting arrays, finding the second largest element, checking Armstrong numbers, printing patterns, and more, along with explanations and variable distribution tables. The project acknowledges the support of teachers, parents, and friends in its completion.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMPUTER PROJECT

Name: Subhrajit Halder


Class: 10
Section: A
Scholar: D.S
Scholar Id: 14-0368
Session: 2025-26
ACKNOWLEDGEMENT
I would like to take this opportunity to express my sincere
gratitude to all those who have guided and supported me in the
successful completion of this Computer Project.
First and foremost, I am deeply thankful to my subject teacher,
Debanjana mam, for their valuable guidance, encouragement, and
continuous support throughout the project. Their expert
suggestions and constructive feedback have been instrumental in
enhancing the quality of my work.
A heartfelt thanks to my parents and friends, whose constant
encouragement, patience, and moral support gave me the
motivation to complete this project with dedication.
Finally, I extend my gratitude to all those who directly or indirectly
contributed to the successful completion of this project.
This project has been a great learning experience, and I sincerely
hope it proves useful and informative for the readers.
Q. Program to sort an array input by user (numbers, letters, or characters), The sorting
will be done in ascending order based on ASCII values.

Source Code :

import [Link];
class SimpleArraySort {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take array length
[Link]("Enter the number of elements: ");
int n = [Link]();
// Step 2: Create array of characters (so it can handle numbers, letters, or symbols)
char[] arr = new char[n];
// Step 3: Take input
[Link]("Enter the elements (characters, numbers, or letters): ");
for (int i = 0; i < n; i++) {
arr[i] = [Link]().charAt(0); // take only first character
}
// Step 4: Sort array using Bubble Sort (ASCII order)
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap
char temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
} } }
// Step 5: Display sorted array
[Link]("Sorted array in ascending ASCII order: ");
for (int i = 0; i < n; i++) {
[Link](arr[i] + " ");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description


Stores the number of elements in the array
n int
entered by the user.
Character array that stores the elements
arr char[] (letters, digits, or symbols) input by the
user.
Loop control variable used in the for loops
i int
(outer loop for input and bubble sort).
Loop control variable used in the inner
j int loop for comparing adjacent elements
during bubble sort.
Temporary variable used for swapping
temp char
elements while sorting.
Q. Program to find the SECOND LARGEST unique element in an array

Source Code :

import [Link];
public class SecondLargest {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take array length
[Link]("Enter the number of elements: ");
int n = [Link]();
int[] arr = new int[n];
// Step 2: Take array input
[Link]("Enter the array elements: ");
for (int i = 0; i < n; i++) {
arr[i] = [Link]();
}
// Step 3: Find largest and second largest manually
int largest = Integer.MIN_VALUE;
int secondLargest = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
if (arr[i] > largest) {
// Update both
secondLargest = largest;
largest = arr[i];
} else if (arr[i] > secondLargest && arr[i] != largest) {
secondLargest = arr[i];
}
}
// Step 4: Display result
if (secondLargest == Integer.MIN_VALUE) {
[Link]("No second largest element (all elements same or only one
element).");
} else {
[Link]("The second largest element is: " + secondLargest);
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Stores the number of elements in the


n int
array entered by the user.

arr int[] Integer array that stores the input


elements given by the user.

i int Loop control variable used in for loops


for array input and traversal.
Stores the largest element in the array,
largest int initialized with Integer.MIN_VALUE
(smallest possible integer).
Stores the second largest unique
secondLargest int element in the array, also initialized
with Integer.MIN_VALUE.
Q. Program to check if a number is an Armstrong Number.
Example: 153 = 1^3 + 5^3 + 3^3 = 153

Source Code :

import [Link];
public class ArmstrongCheck {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take number input
[Link]("Enter a number: ");
int num = [Link]();
// Step 2: Store original number
int original = num;
int sum = 0;
// Step 3: Count digits
int digits = 0;
for (int temp = num; temp > 0; temp /= 10) {
digits++;
}
// Step 4: Calculate sum of power of digits
for (int temp = num; temp > 0; temp /= 10) {
int digit = temp % 10;
// Raise digit to the power of "digits"
int power = 1;
for (int i = 0; i < digits; i++) {
power *= digit;
}
sum += power;
}
// Step 5: Check Armstrong condition
if (sum == original) {
[Link](original + " is an Armstrong Number.");
} else {
[Link](original + " is NOT an Armstrong Number.");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

num int Stores the number entered by the user.

original int Stores the original number to compare


later.

sum int Stores the sum of each digit raised to


the power of the number of digits.
digits int Counts how many digits the number has.
Temporary variable used while
temp int
extracting digits during loops.
Stores the last digit extracted from temp
digit int
(using % 10).
Stores the result of raising a single digit
power int
to the power digits.
Loop control variable used to compute
i int
the power of each digit.
Q. To print a hollow diamond pattern based on user input.

Source Code :

import [Link];
public class HollowDiamondPattern {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of rows for half diamond: ");
int n = [Link]();
// Upper half of diamond
for (int i = 1; i <= n; i++) {
// Print spaces
for (int j = 1; j <= n - i; j++) {
[Link](" ");
}
// Print stars and spaces inside
for (int j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
[Link]("*");
} else {
[Link](" ");
}
}
[Link]();
}
// Lower half of diamond
for (int i = n - 1; i >= 1; i--) {
// Print spaces
for (int j = 1; j <= n - i; j++) {
[Link](" ");
}
// Print stars and spaces inside
for (int j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
[Link]("*");
} else {
[Link](" ");
}
}
[Link]();
}
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

n int Number of rows for the upper half of the


diamond (half diamond height).
Loop control variable for iterating
i int through rows (used in both upper and
lower halves).
Loop control variable for iterating
j int through columns (used for printing
spaces and stars in each row).
Q. To check is a string entered is Palindrome.

Source Code :

import [Link];
public class PalindromeString {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take string input
[Link]("Enter a string: ");
String str = [Link]();
// Step 2: Remove spaces and convert to lowercase for clean comparison
String clean = "";
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch != ' ') {
// convert uppercase to lowercase manually (ASCII trick)
if (ch >= 'A' && ch <= 'Z') {
ch = (char)(ch + 32);
}
clean += ch;
}
}
// Step 3: Check palindrome manually
boolean isPalindrome = true;
int n = [Link]();
for (int i = 0; i < n / 2; i++) {
if ([Link](i) != [Link](n - 1 - i)) {
isPalindrome = false;
break;
}
}
// Step 4: Print result
if (isPalindrome) {
[Link]("\"" + str + "\" is a Palindrome String.");
} else {
[Link]("\"" + str + "\" is NOT a Palindrome String.");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Stores the original input string entered by


str String
the user.
Stores the processed version of the input
clean String string (spaces removed, converted to
lowercase).

ch char Stores each character of str temporarily


while iterating.
Flag variable that becomes false if the string
isPalindrome boolean
is not a palindrome. Default is true.

n int Stores the length of the processed string


clean.
Loop control variable for traversing
i int
characters from both ends of the string.
Q. To find the first non-repeating character found in the entered String.

Source Code :

import [Link];
public class FirstNonRepeating {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take string input
[Link]("Enter a string: ");
String str = [Link]();
char result = '\0'; // stores the answer (default empty)
// Step 2: Loop through each character
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
// Ignore spaces
if (ch == ' ') continue;
// Step 3: Count frequency of ch
int count = 0;
for (int j = 0; j < [Link](); j++) {
if ([Link](j) == ch) {
count++;
}
}
// Step 4: If count is 1 → found first non-repeating char
if (count == 1) {
result = ch;
break;
}
}
// Step 5: Print result
if (result == '\0') {
[Link]("No non-repeating character found.");
} else {
[Link]("The first non-repeating character is: " + result);
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Distribution

str String Stores the input string entered by the user.


Stores the first non-repeating character
result char found (initialized to '\0' which means "no
character").

i int Loop control variable for traversing each


character in the outer loop.
Loop control variable for traversing the
j int string in the inner loop to count frequency
of a character.
Stores the current character being checked
ch char
from the input string.
Stores the frequency of the current character
count int
ch in the string.
Q. To print a String pattern, in a right angled triangle.

Source Code :

import [Link];
public class StringTrianglePattern {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Take string input
[Link]("Enter a string: ");
String str = [Link]();
// Step 2: Print pattern
for (int i = 0; i < [Link](); i++) {
for (int j = 0; j <= i; j++) {
[Link]([Link](j));
}
[Link]();
}
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

str String Stores the input string entered by the user.


Loop control variable for rows (decides how
i int
many characters to print in each row).
Loop control variable for columns (prints
j int
characters of the string up to i).
Q. Define a class to accept a String and Print if it is a Super string or not. A String is
Super if the number of uppercase letters are equal to the number of lower case letters.
[Use Character & String methods only] Example : “COmmITmeNt” Number of
Uppercase letters – 5 Number of Lowercase letters – 5 String is a Super String.

Source Code :

import [Link];
public class SuperString {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Accept string input
[Link]("Enter a string: ");
String str = [Link]();
int upperCount = 0;
int lowerCount = 0;
// Step 2: Traverse string and count
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
upperCount++;
} else if ([Link](ch)) {
lowerCount++;
}
}
// Step 3: Display results
[Link]("Number of Uppercase letters = " + upperCount);
[Link]("Number of Lowercase letters = " + lowerCount);
if (upperCount == lowerCount) {
[Link]("String is a Super String.");
} else {
[Link]("String is NOT a Super String.");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Stores the input string entered by the


str String
user.
Stores the count of uppercase letters in
upperCount int
the string.
Stores the count of lowercase letters in
lowerCount int
the string.
Loop control variable for traversing each
i int
character of the string.
Stores the current character from the
ch char string for checking
uppercase/lowercase.
Q. To take input of a number, and calculate the sum of the largest and the smallest
digits, and give the suitable output as “even”, or “odd”.

Source Code :

import [Link];
public class DigitSumCheck {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Input number
[Link]("Enter a number: ");
int num = [Link]();
int largest = 0; // initialize to smallest possible digit
int smallest = 9; // initialize to largest possible digit
int temp = num; // store original number
// Step 2: Extract digits using for loop (division method)
for (; temp > 0; temp = temp / 10) {
int digit = temp % 10;
// check for largest digit
if (digit > largest) {
largest = digit;
}
// check for smallest digit
if (digit < smallest) {
smallest = digit;
}
}
// Step 3: Print largest and smallest digit
[Link]("Number: " + num);
[Link]("Largest digit: " + largest);
[Link]("Smallest digit: " + smallest);
// Step 4: Check even or odd
int sum = largest + smallest;
if (sum % 2 == 0) {
[Link]("Sum is even");
} else {
[Link]("Sum is odd");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description


num int Stores the number entered by the user.
Stores the largest digit found in the number
largest int
(initialized to 0).

smallest int Stores the smallest digit found in the number


(initialized to 9).
Temporary variable used to extract digits
temp int
from num.
Stores the current digit extracted from temp
digit int
during each iteration.
Stores the sum of the largest and smallest
sum int
digits to check if even or odd.
Q. Define a class to initialise the following data in an array. Search for a given character
input by the user, using the Binary Search technique. Print “Search Successful” if the
character is found otherwise print “Search is not Successful”.
‘A’, ‘H’, ‘N’, ‘P’, ‘S’, ’U’, ‘W’, ‘Y’, ‘Z’, ‘b’, ‘d’

Source Code :

import [Link];
public class CharacterBinarySearch {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Step 1: Initialize sorted array
char[] arr = {'A', 'H', 'N', 'P', 'S', 'U', 'W', 'Y', 'Z', 'b', 'd'};
// Step 2: Input character to search
[Link]("Enter a character to search: ");
char key = [Link]().charAt(0);
// Step 3: Binary Search logic
int low = 0;
int high = [Link] - 1;
boolean found = false;
for (; low <= high;) {
int mid = (low + high) / 2;
if (arr[mid] == key) {
found = true;
break; // character found
} else if (arr[mid] < key) {
low = mid + 1;
} else {
high = mid - 1;
}
}
// Step 4: Print result
if (found) {
[Link]("Search Successful");
} else {
[Link]("Search is not Successful");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

arr char[] Predefined sorted array of characters to


search in.
Character entered by the user to search in the
key char
array.
Stores the lower bound index of the current
low int
search range.
Stores the upper bound index of the current
high int
search range.
Stores the middle index of the current search
mid int
range.
Flag to indicate if the search key is found
found boolean
(true) or not (false).
Q.

Source Code :

import [Link];
public class ArrayNorm {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[][] arr = new int[4][4]; // 4x4 array
int sumOfSquares = 0;
// Step 1: Accept array input
[Link]("Enter 16 integers for 4x4 array:");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
arr[i][j] = [Link]();
}
}
// Step 2: Calculate sum of squares
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
sumOfSquares += arr[i][j] * arr[i][j];
}
}
// Step 3: Calculate norm
double norm = [Link](sumOfSquares);
// Step 4: Display results
[Link]("Sum of squares of elements = " + sumOfSquares);
[Link]("NORM = " + norm);
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

4x4 integer array storing the elements


arr int[][]
entered by the user.
Stores the sum of squares of all elements of
sumOfSquares int
the array.
i int Loop control variable for row iteration.
j int Loop control variable for column iteration.

norm double Stores the norm of the array, calculated as


square root of sumOfSquares.
Q. Define a class to overload the method print( ) as follows:
void print ( ) – To print the given format using nested loops.

@#@#@
@#@#@
@#@#@
@#@#@

double print(double a, double b) – To display the sum of numbers between a and


b with difference of 0.5.

e.g. if a = 1.0, b = 4.0


output is: 1.0 + 1.5 + 2.0 + 2.5 + ……………. + 4.0

int print(char ch1, char ch2) –


compare the two characters and return the ASCII code of the largest character.

Source Code :

import [Link];
public class OverloadPrint {
// 1. Print pattern using nested loops
void print() {
for (int i = 1; i <= 4; i++) { // 4 rows
for (int j = 1; j <= 5; j++) { // 5 characters per row
if (j % 2 == 1) {
[Link]("@");
} else {
[Link]("#");
}
}
[Link]();
}
}
// 2. Sum numbers from a to b with step 0.5
double print(double a, double b) {
double sum = 0.0;
[Link]("Numbers: ");
for (double i = a; i <= b; i += 0.5) {
sum += i;
[Link](i);
if (i + 0.5 <= b) {
[Link](" + ");
}
}
[Link]();
[Link]("Sum = " + sum);
return sum;
}
// 3. Compare two characters and return ASCII of larger
int print(char ch1, char ch2) {
int ascii1 = (int) ch1;
int ascii2 = (int) ch2;
if (ascii1 >= ascii2) {
[Link]("Larger character: " + ch1 + " (ASCII " + ascii1 + ")");
return ascii1;
} else {
[Link]("Larger character: " + ch2 + " (ASCII " + ascii2 + ")");
return ascii2;
}
}
// Main method to take inputs from user
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
OverloadPrint op = new OverloadPrint();
// 1. Print pattern
[Link]("Pattern:");
[Link]();
// 2. Sum of numbers from a to b with 0.5 step
[Link]("\nSum with step 0.5:");
[Link]("Enter starting number (a): ");
double a = [Link]();
[Link]("Enter ending number (b): ");
double b = [Link]();
[Link](a, b);
// 3. Compare characters
[Link]("\nCompare characters:");
[Link]("Enter first character: ");
char ch1 = [Link]().charAt(0);
[Link]("Enter second character: ");
char ch2 = [Link]().charAt(0);
[Link](ch1, ch2);
}
}
Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description


Object of the OverloadPrint class to call the
op OverloadPrint
overloaded print methods.
Loop control variable used in nested loops
i int
(pattern printing).
Loop control variable used in nested loops
i double
(summation).
Loop control variable used in nested loop
j int
for columns in pattern printing.
a double Starting number for the sum calculation.
b double Ending number for the sum calculation.
Stores the sum of numbers from a to b with
sum double
0.5 step.
First character input by the user for
ch1 char
comparison.
Second character input by the user for
ch2 char
comparison.
ascii1 int ASCII value of the first character.
ascii2 int ASCII value of the second character.
Q. Define a class named CloudStorage with the following specifications:

• Member Variables:
int acno - stores the user's account number.
int space - stores the amount of storage space in GB purchased by the user.
double bill - stores the total price to be paid by the user.

• Member Methods: - - -
void accept() - prompts the user to input their account number and
storage space using Scanner class methods only.
void calculate() - calculates the bill total price based on the storage space
Storage range Price per GB (Rs)

First 15 GB 15
Next 15 GB 13
Above 30 GB 11

void display() - displays the account number, storage space and bill to be paid.

Write a main method to create an object of the class and invoke the methods of the
class with respect to the object.
Source Code :

import [Link];
public class CloudStorage {
// Member variables
int acno;
int space;
double bill;
// Method to accept user input
void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter account number: ");
acno = [Link]();
[Link]("Enter storage space purchased (in GB): ");
space = [Link]();
// Do not close Scanner here to avoid closing [Link]
}
// Method to calculate bill based on storage
void calculate() {
bill = 0.0;
if (space <= 15) {
bill = space * 15; // First 15 GB
} else if (space <= 30) {
bill = 15 * 15 + (space - 15) * 13; // First 15 + next
} else {
bill = 15 * 15 + 15 * 13 + (space - 30) * 11; // Above 30
}
}
// Method to display account details and bill
void display() {
[Link]("\n--- Cloud Storage Bill ---");
[Link]("Account Number: " + acno);
[Link]("Storage Space Purchased: " + space + " GB");
[Link]("Total Bill to be Paid: Rs " + bill);
}
// Main method to test the class
public static void main(String[] args) {
CloudStorage cs = new CloudStorage();
[Link](); // Accept account number and storage
[Link](); // Calculate bill
[Link](); // Display details
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

Stores the account number entered by the


acno int
user.

space int Stores the amount of cloud storage space


purchased (in GB).
Stores the total calculated bill amount for
bill double
the cloud storage.
Object of the CloudStorage class used to
cs CloudStorage call methods accept(), calculate(), and
display().
Q. Define a class named DataPlan with the following specifications:
Member Variables:
• int userId — stores the user ID number
• int dataUsed — stores data usage in GB
• double totalBill — stores total bill
Member Methods:
• Parameterized Constructor → to initialize userId and dataUsed.
• void calculate() → calculates the monthly bill as per the following rates:

Data Range Rate per GB


(Rs)
First 10 GB 20
Next 10 GB 15
Above 20 GB 10

• void display() → displays all user details with the calculated bill.
In the main method,
• Accept details for multiple users using a loop and constructor.
• Call the calculate() and display() methods for each user.
Source Code :

import [Link];
public class DataPlan {
int userId;
int dataUsed;
double totalBill;
// Parameterized Constructor
DataPlan(int id, int data) {
userId = id;
dataUsed = data;
totalBill = 0.0;
}
// Method to calculate bill
void calculate() {
if (dataUsed <= 10) {
totalBill = dataUsed * 20;
} else if (dataUsed <= 20) {
totalBill = (10 * 20) + (dataUsed - 10) * 15;
} else {
totalBill = (10 * 20) + (10 * 15) + (dataUsed - 20) * 10;
}
}
// Method to display details
void display() {
[Link]("\n--- Monthly Data Plan Bill ---");
[Link]("User ID: " + userId);
[Link]("Data Used: " + dataUsed + " GB");
[Link]("Total Bill: Rs " + totalBill);
}
// Main method
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of users: ");
int n = [Link]();
DataPlan[] users = new DataPlan[n];
// Accept user details through constructor
for (int i = 0; i < n; i++) {
[Link]("\n--- Enter details for User " + (i + 1) + " ---");
[Link]("Enter User ID: ");
int id = [Link]();
[Link]("Enter Data Used (in GB): ");
int data = [Link]();

users[i] = new DataPlan(id, data); // constructor called


users[i].calculate();
}
// Display details for all users
[Link]("\n==============================");
[Link](" MONTHLY BILL LIST ");
[Link]("==============================");
for (int i = 0; i < n; i++) {
users[i].display();
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

userId int Stores the unique ID of each user.


Stores the total data used (in GB) by a
dataUsed int
user.
Stores the total calculated bill for that
totalBill double
user.
Temporarily stores the user ID entered by
id int
the user (used to create DataPlan object).
Temporarily stores the data used entered
data int by the user (used to create DataPlan
object).
n int Stores the total number of users.
Array of DataPlan objects, each storing
users[] DataPlan[]
data for one user.
Q. Define a class named DigitAnalyzer with the following specifications:
Member Variables:
• int num — to store the number
• int sumOdd — to store the sum of odd digits
• int prodEven — to store the product of even digits
Member Methods:
• Constructor → accepts the number using Scanner.
• void calculate() → finds the sum of odd digits and product of even digits.
• void display() → displays both results.
Write the main method to create an object of the class and call the methods.

Source Code :

import [Link];
public class DigitAnalyzer {
int num;
int sumOdd;
int prodEven;
// Constructor to accept number
DigitAnalyzer() {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
num = [Link]();
sumOdd = 0;
prodEven = 1; // start with 1 because product identity is 1
}
// Method to calculate
void calculate() {
int n = num;
while (n > 0) {
int d = n % 10;
if (d % 2 == 0)
prodEven *= d;
else
sumOdd += d;
n /= 10;
}
}
// Method to display
void display() {
[Link]("\nNumber: " + num);
[Link]("Sum of odd digits = " + sumOdd);
[Link]("Product of even digits = " + prodEven);
}
// Main method
public static void main(String[] args) {
DigitAnalyzer obj = new DigitAnalyzer();
[Link]();
[Link]();
}}

Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

num int Stores the number entered by the user.


Stores the sum of all odd digits present in the
sumOdd int
number.
Stores the product of all even digits present in
prodEven int
the number.
Temporary variable used to extract digits of
n int
num one by one.
Stores the current digit extracted from the
d int
number during processing.
obj DigitAnalyzer Object of the class used to call methods.
Q. Write a program to input a string, cast it to upper, replace each vowel with the next
character, and the consonant with the previous character.

Source Code :

import [Link];
public class StringReplace {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a string: ");
String str = [Link]().toUpperCase();
String result = "";
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if ([Link](ch)) {
if ("AEIOU".indexOf(ch) != -1) {
// Vowel → next character
if (ch == 'U')
result += 'V';
else
result += (char) (ch + 1);
} else {
// Consonant → previous character
if (ch == 'A')
result += 'Z';
else
result += (char) (ch - 1);
}
} else {
// Keep non-letter characters same
result += ch;
}
}
[Link]("Modified String: " + result);
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Stores the user-input string converted to


str String
uppercase.
Stores the newly formed (modified) string after
result String
replacing each character.
i int Loop counter for traversing the string.
Stores each character of the string being
ch char
processed.
Q. Input a number, and check if the number is a SUPERSPY number or not.
A SUPERSPY NUMBER is a number whose number of digits is same as the sum of its
digits.
Example : 1021, number of digits = 4. 1+0+2+1 = 4. 1021 is a SUPERSPY NUMBER.

Source Code :

import [Link];
public class SuperSpyNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int sum = 0, product = 1, temp = num;
while (temp > 0) {
int digit = temp % 10;
sum += digit;
product *= digit;
temp /= 10;
}
if (sum == product)
[Link](num + " is a SUPERSPY number.");
else
[Link](num + " is NOT a SUPERSPY number.");
}}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

num int Stores the original number entered by the user.


sum int Stores the sum of all digits of the number.
product int Stores the product of all digits of the number.
temp int Temporary copy of the number used for digit extraction.
digit int Stores the current digit extracted from the number.
Q. Write a Java program to check whether a number is a Krishnamurthy number.
145 → 1! + 4! + 5! = 1 + 24 + 120 = 145 → Krishnamurthy number

Source Code :

import [Link];
public class Krishnamurthy {
// Method to calculate factorial of a digit
static int factorial(int n) {
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int sum = 0, temp = num;
while (temp > 0) {
int digit = temp % 10;
sum += factorial(digit);
temp /= 10;
}
if (sum == num)
[Link](num + " is a KRISHNAMURTHY number.");
else
[Link](num + " is NOT a KRISHNAMURTHY number.");
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

sc Scanner Used to take input from the user.


num int Stores the number entered by the user.
sum int Stores the sum of factorials of digits of num.
temp int Temporary copy of num used to extract digits.
digit int Stores each digit of num during processing.
i int Loop counter used in the factorial method.
fact int Stores factorial of a digit in factorial() method.
Q. Input a number, and check whether it is a BUZZ number.
A BUZZ number is one either divisible by 7 or ends with 7.

Source Code :

import [Link];
public class BuzzNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
if (num % 7 == 0 || num % 10 == 7) {
[Link](num + " is a BUZZ number.");
} else {
[Link](num + " is NOT a BUZZ number.");
}
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

num int Stores the number entered by the user.


Q. Define a class to accept a string and convert it into uppercase. Count and display the
number of vowels in it.
Input: robotics
Output: ROBOTICS
Number of vowels: 3

Source Code :

import [Link];
public class VowelCounter {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Accept input string
[Link]("Enter a string: ");
String str = [Link]();
// Convert to uppercase
String upperStr = [Link]();
[Link]("Uppercase: " + upperStr);
// Count vowels
int vowelCount = 0;
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
vowelCount++;
}
}
// Display number of vowels
[Link]("Number of vowels: " + vowelCount);
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

str String Stores the original string input by the user.


Stores the uppercase version of str for easier
upperStr String
vowel comparison.
vowelCount int Counts the number of vowels in the string.
i int Loop counter for traversing the string.
ch char Current character being checked in the loop.
Q. Define a class to accept values into a 3×3 array and check if it is a special array.
An array is a special array if the sum of the even elements = sum of the odd
elements.
Example: A[][]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}};
Sum of even elements = 4+6+2+4+2 =18
Sum of odd elements= 5+5+3+5=18

Source Code :

import [Link];
public class SpecialArray {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[][] arr = new int[3][3];
int sumEven = 0, sumOdd = 0;
// Accept values for the 3x3 array
[Link]("Enter 9 elements for a 3x3 array:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] = [Link]();
// Check if element is even or odd and add to respective sum
if (arr[i][j] % 2 == 0)
sumEven += arr[i][j];
else
sumOdd += arr[i][j];
}
}
// Display the sums
[Link]("Sum of even elements = " + sumEven);
[Link]("Sum of odd elements = " + sumOdd);
// Check if array is special
if (sumEven == sumOdd)
[Link]("The array is a SPECIAL ARRAY.");
else
[Link]("The array is NOT a special array.");
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

3x3 array to store the elements entered by


arr int[][]
the user.
Stores the sum of all even elements in the
sumEven int
array.
Stores the sum of all odd elements in the
sumOdd int
array.
i int Loop counter for rows of the array.
j int Loop counter for columns of the array.
Q. Define a class to accept a 3 digit number and check whether it is a duck number or
not. Note: A number is a duck number if it has zero in it.

Source Code :

import [Link];
public class DuckNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a 3-digit number: ");
int num = [Link]();
// Check if number is actually 3-digit
if (num < 100 || num > 999) {
[Link]("Error: Number is not a 3-digit number.");
return;
}
int temp = num;
boolean isDuck = false;
// Loop through each digit
for (int i = 0; i < 3; i++) {
int digit = temp % 10;
if (digit == 0) {
isDuck = true;
break; // no need to check further
}
temp /= 10;
}
// Display result
if (isDuck)
[Link](num + " is a DUCK number.");
else
[Link](num + " is NOT a DUCK number.");
}
}
Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

num int Stores the 3-digit number entered by the user.


Temporary variable to extract and process
temp int
digits of num.
Flag to indicate whether the number is a Duck
isDuck boolean
number (true) or not (false).
i int Loop counter for iterating through the 3 digits.
Stores the current digit of the number being
digit int
checked.
Q.

Source Code :

import [Link];
public class DisplayOverload {
// 1. Display pattern using nested loops
void display() {
for (int i = 1; i <= 5; i++) { // 5 rows
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
[Link]();
}
}
// 2. Display square roots of each digit of a number
void display(int n) {
String numStr = [Link](n); // Convert number to string to get each digit
for (int i = 0; i < [Link](); i++) {
int digit = [Link](i) - '0'; // Convert char to integer
double sqrtDigit = [Link](digit);
[Link](sqrtDigit);
}
}
// Main method to test
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
DisplayOverload obj = new DisplayOverload();
// 1. Display pattern
[Link]("Pattern:");
[Link]();
// 2. Display square roots
[Link]("\nEnter a number to find square roots of its digits: ");
int number = [Link]();
[Link]("Square roots of digits:");
[Link](number);
}}
Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Object of the DisplayOverload class used to


obj DisplayOverload
call overloaded methods.
Number entered by the user to calculate
number int
square roots of its digits.
Parameter of overloaded display(int n)
n int method representing the number whose
digits’ square roots are calculated.
String representation of n to access each
numStr String
digit.
Loop counter for rows (in display()) or for
i int
digits of numStr (in display(int n)).
Loop counter for printing numbers in the
j int
pattern.
digit int Stores the individual digit extracted from n.
sqrtDigit double Stores the square root of the digit.
Q.

Source Code :

import [Link];
public class Eshop {
// Member variables
String name;
double price;
double netAmount;
// Method to accept item details
void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter the name of the item: ");
name = [Link]();
[Link]("Enter the price of the item: ");
price = [Link]();
}
// Method to calculate net amount based on discount slabs
void calculate() {
if (price >= 1000 && price <= 25000) {
netAmount = price - (price * 5.0 / 100);
} else if (price >= 25001 && price <= 57000) {
netAmount = price - (price * 7.5 / 100);
} else if (price >= 57001 && price <= 100000) {
netAmount = price - (price * 10.0 / 100);
} else if (price > 100000) {
netAmount = price - (price * 15.0 / 100);
} else {
netAmount = price; // No discount for price below 1000
}
}
// Method to display item and net amount
void display() {
[Link]("\n--- Bill Details ---");
[Link]("Item Name: " + name);
[Link]("Net Amount to be Paid: Rs " + netAmount);
}
// Main method
public static void main(String[] args) {
Eshop item = new Eshop();
[Link]();
[Link]();
[Link]();
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

name String Stores the name of the item entered by the user.
price double Stores the price of the item entered by the user.
Stores the final amount after applying discounts
netAmount double
based on price slabs.
Object of Eshop class used in main() to access
item Eshop
methods accept(), calculate(), and display().
Q. Define a class to input a word and reverse it and print in caps lock and print the
number of vowels.

Source Code :

import [Link];
public class ReverseWord {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a word: ");
String word = [Link]().toUpperCase(); // convert to uppercase
int vowels = 0;
[Link]("Reversed word: ");
for (int i = [Link]() - 1; i >= 0; i--) {
char ch = [Link](i);
[Link](ch);
// Count vowels
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
vowels++;
}
}
[Link]("\nNumber of vowels: " + vowels);
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Purpose / Description

Stores the word entered by the user (converted to


word String
uppercase).
Counter to keep track of the number of vowels in
vowels int
the word.
Loop index used in the reverse traversal of the
i int
word.
Stores the current character being processed in
ch char
the loop.
Q. Write a program, to input a number and check whether the number is a DUDENCY
NUMBER.
A DUDENCY NUMBER, is a number whose sum of the digits cube is the number itself

Source Code :

import [Link];
public class DudeneyNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int temp = num, sum = 0;
// Using while loop to calculate sum of cubes of digits
while (temp > 0) {
int d = temp % 10;
sum += d;
temp /= 10;
}
// Check if sum’s cube equals original number
[Link](((sum*sum*sum) == num) ? (num + " is a DUDENEY
number.")
: (num + " is NOT a DUDENEY number."));
}
}
Output Terminal :

Variable Distribution Table :

Variable Name Data Type Description

num int Stores the original number entered by the user.


Temporary variable used to extract digits from
temp int
num in the loop.
Stores the sum of cube of the sum of the digits
sum int
of num.
Current digit being processed in the while
d int
loop.
Q. Overload the method magic:

magic(int n):
1
23
456 …….. till n

magic(int a, char ch):


This will make the square of the number, and the numbers before it from 1 for s,
or S, and cube of the number and the numbers before it from 1 for c, or C.

Source Code :

import [Link];
public class MagicMethods {
// 1. magic(int n) → prints numbers in increasing sequence till n
void magic(int n) {
int count = 1;
for (int i = 1; count <= n; i++) {
for (int j = 1; j <= i && count <= n; j++) {
[Link](count);
count++;
}
[Link]();
}
}
// 2. magic(int a, char ch) → square or cube depending on ch
void magic(int a, char ch) {
for (int i = 1; i <= a; i++) {
if (ch == 's' || ch == 'S') {
[Link](i + " squared = " + (i * i));
} else if (ch == 'c' || ch == 'C') {
[Link](i + " cubed = " + (i * i * i));
} else {
[Link]("Invalid character! Use S/s for square, C/c for cube.");
break;
}
}
}
// Main method to test
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
MagicMethods obj = new MagicMethods();
// Test 1: magic(int n)
[Link]("Enter a number for magic(int n): ");
int n = [Link]();
[Link]("\nMagic Pattern:");
[Link](n);
// Test 2: magic(int a, char ch)
[Link]("\nEnter a number for magic(int a, char ch): ");
int a = [Link]();
[Link]("Enter character (S/s for square, C/c for cube): ");
char ch = [Link]().charAt(0);
[Link]();
[Link](a, ch);
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

Object of the MagicMethods class used to call


obj MagicMethods
overloaded magic methods.
Input number for generating the increasing
n int
sequence pattern in magic(int n).
Input number up to which squares or cubes
a int
are printed in magic(int a, char ch).
Character to decide operation: 'S'/'s' for
ch char
square, 'C'/'c' for cube.
Counter for printing numbers in increasing
count int
sequence in magic(int n).
Loop control variable for outer loops in both
i int
methods.
Loop control variable for inner loop in
j int
magic(int n) to print numbers.
Q. Matrix Treasure Hunt :
User enters a 4X4 matrix. Program searches for the “treasure”, defined as the largest
prime number in the matrix. Prints its position(s) in the matrix.

Source Code :

import [Link];
public class MatrixTreasureHunt {
// Method to check if a number is prime
static boolean isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[][] matrix = new int[4][4];
// Step 1: Input 4x4 matrix
[Link]("Enter 16 numbers (1-100) for a 4x4 matrix:");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = [Link]();
}
}
// Step 2: Find largest prime
int maxPrime = -1;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (isPrime(matrix[i][j]) && matrix[i][j] > maxPrime) {
maxPrime = matrix[i][j];
}
}
}
// Step 3: Display result
if (maxPrime == -1) {
[Link]("No prime numbers (treasure) found in the matrix.");
} else {
[Link]("Treasure found! Largest prime = " + maxPrime);
[Link]("Positions of treasure in the matrix:");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (matrix[i][j] == maxPrime) {
[Link]("Row " + (i + 1) + ", Column " + (j + 1));
}
}
}
} }}
Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

4x4 integer matrix storing user-input numbers


matrix int[][]
(1–100).
i int Loop control variable for rows.
j int Loop control variable for columns.
Stores the largest prime number (the "treasure")
maxPrime int
found in the matrix. Initialized to -1.
Local variable in isPrime method representing the
n int
number to check for primality.
Individual element of the matrix at row i and
matrix[i][j] int
column j. Used for both input and comparison.
Q. User enters a word (e.g., JAVA).
Program prints a pyramid where:
• Each row displays letters from the word up to that row.
• Under each letter, it prints the ASCII value of that letter.

Source Code :

import [Link];
public class AlphabetPyramid {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a word: ");
String s = [Link]();
for (int i = 0; i < [Link](); i++) {
// Print letters
for (int j = 0; j <= i; j++) {
[Link]([Link](j) + " ");
}
[Link]();
// Print ASCII values
for (int j = 0; j <= i; j++) {
[Link]((int) [Link](j) + " ");
}
[Link]("\n");
}
}
}

Output Terminal :
Variable Distribution Table :

Variable Name Data Type Description

s String Stores the word entered by the user.


Loop control variable for the number of rows
i int
in the pyramid (outer loop).
Loop control variable for characters in a row
j int
(inner loop).
The character at position j in string s. Used to
[Link](j) char
print letters and their ASCII values.
Q. Print all “Happy Numbers” up to N using only for loops and minimal variables.
A Happy Number is a number that eventually reaches 1 when replaced by the sum of
the squares of its digits repeatedly.

Source Code :

import [Link];
public class HappyNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter N: ");
int N = [Link]();
for (int i = 1; i <= N; i++) {
int n = i, sum;
for (int k = 0; k != 1 && k != 4; ) { // 4 → unhappy loop
sum = 0;
for (int t = n; t > 0; t /= 10)
sum += (t % 10) * (t % 10);
n = sum;
k = n;
}
if (n == 1) [Link](i + " is a Happy Number");
}
}
}
Output Terminal :
Variable Distribution Table :

Variable Name Data Type Purpose / Description

The upper limit (1 to N) to check for Happy


N int
Numbers.
Loop control variable for iterating numbers
i int
from 1 to N.
Temporary variable storing the number
n int
being processed to check happiness.
Sum of squares of digits of n during each
sum int
iteration.
Used to detect if n reaches 1 (happy) or 4
k int
(unhappy loop).
Temporary variable used to extract each
t int
digit of n in the inner loop.
CONCLUSION
Through this project, I gained valuable knowledge about the
practical applications of computer science and the concepts I have
studied in class. It not only enhanced my technical understanding
but also improved my problem-solving and analytical skills.
The project helped me realize the importance of accuracy, logical
thinking, and creativity while working with computers. I also
learned how theoretical knowledge can be effectively applied in
real-life situations through coding, designing, and implementation.
Overall, this project was a rewarding experience as it strengthened
my foundation in the subject and encouraged me to explore more
advanced areas of computer science. I am confident that the
knowledge and skills acquired during this work will be beneficial
for my future learning and endeavors.
BIBLIOGRAPHY
The following sources of information were consulted during the
preparation of this Computer Project:

Books:
1. A Das Gupta – APC ICSE Computer Applications (Class 10)
2. Computer Applications Textbook – ICSE Class X, [Orange
Publications]

Websites:
1. [Link]
2. [Link]
compiler
Thank You

You might also like