Program 1 – Armstrong Number
// Program to check whether a given number is an Armstrong number
import [Link];
public class Armstrong_Number {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
// Step 1: Accept the number from the user
[Link]("Enter a number: ");
int n = [Link]();
// Step 2: Create variables to store a copy and the sum of cubes
int temp = n;
int sum = 0;
// Step 3: Loop to extract each digit and find the sum of cubes
while (temp > 0) {
int d = temp % 10; // Extract last digit
sum = sum + (d * d * d); // Add cube of digit
temp = temp / 10; // Remove last digit
// Step 4: Check if the sum of cubes equals the original number
if (sum == n)
[Link](n + " is an Armstrong number");
else
[Link](n + " is not an Armstrong number");
}
Algorithm
Step 1: Start the program
Step 2: Input the number
Step 3: Initialize sum = 0 and temp = n
Step 4: Extract each digit and add its cube to sum
Step 5: Compare sum and n
Step 6: Display whether it is an Armstrong number
Step 7: Stop the program
Variable Description
Variab Data
Description
le Type
n int Input number
Working copy of
temp int
number
Digit extracted from
d int
number
sum int Sum of cubes of digits
Sample Output
Enter a number: 153
153 is an Armstrong number
Program 2 – Neon Number
// Program to check whether a number is a Neon number
import [Link];
public class Neon_Number {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
// Step 1: Accept a number from the user
[Link]("Enter a number: ");
int n = [Link]();
// Step 2: Calculate the square of the number
int sq = n * n;
int sum = 0;
// Step 3: Add the digits of the square
while (sq > 0) {
int d = sq % 10;
sum = sum + d;
sq = sq / 10;
// Step 4: Check if the sum equals the original number
if (sum == n)
[Link](n + " is a Neon number");
else
[Link](n + " is not a Neon number");
Algorithm
Step 1: Start the program
Step 2: Input a number
Step 3: Find its square
Step 4: Add all digits of the square
Step 5: If the sum equals the number, print “Neon number”; otherwise
“Not Neon”
Step 6: Stop the program
Variable Description
Variab Data
Description
le Type
n int Input number
sq int Square of number
d int Extracted digit
Sum of digits of
sum int
square
Sample Output
Enter a number: 9
9 is a Neon number
Program 3 – Buzz Numbers in an Array
// Program to display all Buzz numbers in an array of 10 integers
// A Buzz number is divisible by 7 or ends with 7
import [Link];
public class Buzz_Array {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int a[] = new int[10];
// Step 1: Input 10 integers
[Link]("Enter 10 integers:");
for (int i = 0; i < 10; i++) {
a[i] = [Link]();
// Step 2: Display only the Buzz numbers
[Link]("Buzz numbers are:");
for (int i = 0; i < 10; i++) {
int x = a[i];
if (x % 7 == 0 || x % 10 == 7) {
[Link](x);
Algorithm
Step 1: Start the program
Step 2: Input 10 integers into an array
Step 3: For each element, check if divisible by 7 or ends with 7
Step 4: Display the Buzz numbers
Step 5: Stop the program
Variable Description
Variab Data
Description
le Type
a int[] Array of integers
Current element being
x int
checked
Sample Output
Enter 10 integers:
7 14 27 33 47 70 82 97 100 21
Buzz numbers are:
14
27
47
70
97
21
Program 4 – Merge Two Numbers
// Program to merge two given integers into a single number
import [Link];
public class Merge_Numbers {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
// Step 1: Input two integers
[Link]("Enter the first number: ");
int a = [Link]();
[Link]("Enter the second number: ");
int b = [Link]();
// Step 2: Find the number of digits in second number
int pow = 1;
int temp = b;
while (temp > 0) {
pow = pow * 10;
temp = temp / 10;
// Step 3: Merge the numbers
int merged = (a * pow) + b;
// Step 4: Display merged result
[Link]("Merged number: " + merged);
Algorithm
Step 1: Start the program
Step 2: Input two numbers
Step 3: Count digits in second number
Step 4: Multiply first number by 10^digits and add second
Step 5: Display merged number
Step 6: Stop the program
Variable Description
Variab Data
Description
le Type
a,b int Input numbers
temp int Copy of second number
Power of 10 used for
pow int
merging
merged int Final merged number
Sample Output
Enter the first number: 134
Enter the second number: 96
Merged number: 13496
Program 5 – Sum of Numbers Divisible by 3 or 5
// Program to find sum of numbers divisible by 3 or 5 in an array
import [Link];
public class Sum_Div3or5 {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
int a[] = new int[10];
// Step 1: Input 10 integers
[Link]("Enter 10 integers:");
for (int i = 0; i < 10; i++) {
a[i] = [Link]();
// Step 2: Add numbers divisible by 3 or 5
int sum = 0;
for (int i = 0; i < 10; i++) {
if (a[i] % 3 == 0 || a[i] % 5 == 0)
sum = sum + a[i];
// Step 3: Display sum
[Link]("Sum of numbers divisible by 3 or 5: " + sum);
Algorithm
Step 1: Start the program
Step 2: Input 10 numbers into an array
Step 3: Initialize sum = 0
Step 4: For each number, if divisible by 3 or 5, add to sum
Step 5: Display total sum
Step 6: Stop the program
Variable Description
Variab Data
Description
le Type
a int[] Array of numbers
sum int Total of numbers divisible by
Variab Data
Description
le Type
3 or 5
Sample Output
Enter 10 integers:
3 5 6 7 10 11 12 13 15 20
Sum of numbers divisible by 3 or 5: 86