0% found this document useful (0 votes)
1 views5 pages

Final Practical Project Collection

The document contains Java programs for various mathematical checks, including determining if a number is a Neon Number, finding the Lowest Common Multiple (LCM) of two numbers, checking if a number is a Strong Number, counting the digits in a number, and verifying if a year is a Leap Year. Each section includes a question prompt, Java source code, sample output, and a step-by-step algorithm. These programs demonstrate basic programming concepts and control structures in Java.

Uploaded by

mayank.945532
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)
1 views5 pages

Final Practical Project Collection

The document contains Java programs for various mathematical checks, including determining if a number is a Neon Number, finding the Lowest Common Multiple (LCM) of two numbers, checking if a number is a Strong Number, counting the digits in a number, and verifying if a year is a Leap Year. Each section includes a question prompt, Java source code, sample output, and a step-by-step algorithm. These programs demonstrate basic programming concepts and control structures in Java.

Uploaded by

mayank.945532
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

1.

NEON NUMBER

QUESTION

Write a Java program to check whether a number is a Neon Number or not.


Note: A neon number is a number where the sum of digits of its square is equal to the number itself (e.g., 9 → 92 =
81 → 8 + 1 = 9).

JAVA SOURCE CODE

import [Link].*;

class NeonNumber {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int num, square, sum = 0, digit;

[Link]("Enter a number: ");


num = [Link]();

square = num * num;


while (square > 0) {
digit = square % 10;
sum = sum + digit;
square = square / 10;
}

if (sum == num) {
[Link](num + " is a Neon Number.");
} else {
[Link](num + " is not a Neon Number.");
}
}
}

SAMPLE OUTPUT
Enter a number: 9
9 is a Neon Number.

ALGORITHM
1. Start the program and input a number using Scanner.
2. Calculate the square of the input number.
3. Extract each digit from the square mathematically using the modulo operator.
4. Accumulate the extracted digits into a sum variable.
5. Compare the final sum with the original number.
6. Display the result and stop.

Computer Science Practical Project Collection Page 1


2. LCM OF TWO NUMBERS

QUESTION

Write a Java program to find the Lowest Common Multiple (LCM) of two numbers.

JAVA SOURCE CODE

import [Link].*;

class LCM {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int a, b, max, lcm;

[Link]("Enter two numbers: ");


a = [Link]();
b = [Link]();

max = (a > b) ? a : b;
while (true) {
if (max % a == 0 && max % b == 0) {
lcm = max;
break;
}
max++;
}
[Link]("LCM = " + lcm);
}
}

SAMPLE OUTPUT
Enter two numbers: 12 15
LCM = 60

ALGORITHM
1. Start the program and input two numbers using Scanner.
2. Determine which of the two inputs holds the maximum value.
3. Start an infinite loop beginning from that maximum value upwards.
4. Check if the current number is perfectly divisible by both inputs without any remainder.
5. If true, assign it as the LCM, break the loop, display the final calculation, and stop.

Computer Science Practical Project Collection Page 2


3. STRONG NUMBER

QUESTION

Write a Java program to check whether a number is a Strong Number or not.


Note: A number is called a Strong Number if the sum of the factorials of its digits is equal to the number itself (e.g.,
145 = 1! + 4! + 5!).

JAVA SOURCE CODE

import [Link].*;

class StrongNumber {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int num, temp, digit, sum = 0;

[Link]("Enter a number: ");


num = [Link]();

temp = num;
while (temp > 0) {
digit = temp % 10;
long fact = 1;
for (int i = 1; i <= digit; i++) {
fact = fact * i;
}
sum = sum + (int)fact;
temp = temp / 10;
}

if (sum == num) {
[Link](num + " is a Strong Number.");
} else {
[Link](num + " is not a Strong Number.");
}
}
}

SAMPLE OUTPUT
Enter a number: 145
145 is a Strong Number.

ALGORITHM
1. Start the program and input a number using Scanner.
2. Store the original number in a temporary tracking variable.
3. Extract each digit one by one and pass it through a nested loop to calculate its unique factorial.
4. Add the resulting factorials sequentially to a running sum tracker.
5. Compare the total sum with the original input value, display the validation message, and stop.

Computer Science Practical Project Collection Page 3


4. COUNT DIGITS IN A NUMBER

QUESTION

Write a Java program to count the total number of digits present in an integer.

JAVA SOURCE CODE

import [Link].*;

class CountDigits {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int num, temp, count = 0;

[Link]("Enter a number: ");


num = [Link]();

temp = num;
if (temp == 0) {
count = 1;
} else {
while (temp > 0) {
count++;
temp = temp / 10;
}
}
[Link]("Total number of digits = " + count);
}
}

SAMPLE OUTPUT
Enter a number: 50284
Total number of digits = 5

ALGORITHM
1. Start the program and input a number using Scanner.
2. Initialize a digit counter variable to 0.
3. Account for the zero edge case: if the input is 0, set the count directly to 1.
4. Run a loop that continuously divides the number by 10 to strip digits, incrementing the counter by 1 per step.
5. Terminate when the remaining value becomes zero, print the counter string, and stop.

Computer Science Practical Project Collection Page 4


5. LEAP YEAR CHECK

QUESTION

Write a Java program to check whether a year is a Leap Year or not.

JAVA SOURCE CODE

import [Link].*;

class LeapYear {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int year;

[Link]("Enter a year: ");


year = [Link]();

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


[Link](year + " is a Leap Year.");
} else {
[Link](year + " is not a Leap Year.");
}
}
}

SAMPLE OUTPUT
Enter a year: 2024
2024 is a Leap Year.

ALGORITHM
1. Start the program and input a target year using Scanner.
2. Evaluate if the year is divisible by 4 and not divisible by 100, or if it is directly divisible by 400.
3. Implement these conditions using logical operators (&& and ||) inside an if-else statement.
4. Print whether the input matches leap year conditions based on the logic check.
5. Stop.

Computer Science Practical Project Collection Page 5

You might also like