ISC Computer 30 Programs 2025-2026
ISC Computer 30 Programs 2025-2026
[Link]
Date:
Aim: To write a java program to check whether the given number is an Armstrong
number or not. (An Armstrong Number of n digits is a number that is equal to the sum of the n-th
powers of its digits.)
Algorithm:
1. Start the program.
2. Import the Scanner class to take input.
3. Declare the class ArmstrongNumber.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a number.
7. Store the input number in variable num.
8. Store the original value of num in temp for later comparison.
9. Initialize sum to 0 to store the sum of cubes of digits.
10. Calculate the number of digits (n) in num using a while loop.
11. In a while loop, extract each digit of num.
12. Cube the extracted digit and add it to sum.
13. Reduce num by dividing it by 10 to remove the extracted digit.
14. After the loop ends, check if sum is equal to temp.
15. If true, print the number is Armstrong.
16. Else, print the number is not Armstrong.
17. End the program.
18. Close the scanner.
19. End the method.
20. End the class.
Source Code:
import [Link];
1
public class ArmstrongNumber {
int sum = 0;
int n = 0;
while (temp != 0) {
temp /= 10;
n++;
temp = num; // Reassign the original value of num to temp for calculation
while (temp != 0) {
temp /= 10;
if (sum == num) {
} else {
2
[Link](num + " is not an Armstrong Number.");
[Link]();
Variable Description:
[Link] Variable Type Method Description
Output:
3
Result: Thus the program was successfully run without any error and the output is
verified.
PALINDROME NUMBER
[Link]
Date:
Aim: To write a java program to check whether the given number is a Palindrome number
or not. (A number is said to be a Palindrome number if the reverse of number is equal to
the original number.)
Algorithm:
1. Start the program.
2. Import the Scanner class to take user input.
3. Declare the class PalindromeNumber.
4. Define the main() method.
5. Create a Scanner object for reading input from the user.
6. Prompt the user to enter a number.
7. Store the input number in variable num.
4
8. Initialize reverse to 0 to store the reversed number.
9. Store the original value of num in temp for later comparison.
10. Use a while loop to reverse the digits of num.
11. Extract the last digit of num using modulus (num % 10).
12. Add the extracted digit to reverse by multiplying reverse by 10 and adding the digit.
13. Remove the last digit from num by dividing it by 10.
14. Continue this process until num becomes 0.
15. After the loop ends, check if reverse is equal to temp.
16. If true, print that the number is a Palindrome.
17. Else, print that the number is not a Palindrome.
18. End the program.
19. Close the scanner.
20. End the class.
Source Code:
import [Link];
int reverse = 0;
while (num != 0) {
5
num /= 10;
if (reverse == temp) {
} else {
[Link]();
Variable Description:
[Link] Variable Type Method Description
Output:
Result: Thus the program was successfully run without any error and the Output is
verified
PRONIC NUMBER
[Link]
Date:
Aim: To write a java program to check whether the given number is a Pronic number or
not. (A number is said to be a Pronic number if the product of two consecutive is equal to
the original number.)
Algorithm:
1. Start the program.
7
2. Import the Scanner class to take input from the user.
3. Declare the class PronicNumber.
4. Define the main() method.
5. Create a Scanner object for reading input.
6. Prompt the user to enter a number.
7. Store the entered number in num.
8. Initialize a variable i to 0.
9. Use a while loop to check if i * (i + 1) is less than or equal to num.
10. In the loop, check if i * (i + 1) equals num.
11. If true, print that num is a Pronic Number.
12. If the loop ends without finding a match, print that num is not a Pronic Number.
13. End the program.
14. Close the scanner.
15. End the method.
16. End the class.
Source Code :
import [Link].*;
int n = [Link]();
int c=0;
for(int i=1;i<=n;i++)
if(i*(i+1)==n)
c=1;
8
if(c==1)
[Link]("Pronic Number");
else
Variable Description:
[Link] Variable Type Method Description
Output:
9
Result: Thus the program was successfully run without any error and the Output is
verified.
SPECIAL NUMBER
[Link]: 4
Date:
Aim: To write a java program to check whether the given number is a Special number or
not. (A number is said to be a Special number if the reverse of number is equal to the
original number.)
Algorithm:
1. Start the program.
2. Import the Scanner class to take user input.
3. Declare the class SpecialNumber.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a number.
7. Store the input number in num.
8. Initialize sum to 0 to store the sum of factorials.
10
9. Store the original value of num in temp for comparison.
10. Use a while loop to extract each digit from num.
11. For each digit, calculate its factorial.
12. Add the factorial to sum.
13. After the loop, check if sum equals temp.
14. If true, print that the number is Special.
15. Else, print that the number is not Special.
16. End the program.
17. Close the scanner.
18. End the method.
19. End the class.
20. End the program.
Source Code:
import [Link].*;
int n = [Link]();
int m = n ;
int a,sum=0;
for( ; n>0 ;)
a = n%10;
int fact=1;
11
{
fact = fact*i;
sum=sum+fact;
n=n/10;
if(sum == m)
[Link]("Special Number");
else
Variable Description:
[Link] Variable Type Method Description
Output:
Result: Thus the program was successfully run without any error and the Output is
verified.
PASCAL’S TRIANGLE
[Link]::5
Date:
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class PascalsTriangle.
4. Define the main() method.
5. Create a Scanner object for reading input.
6. Prompt the user to enter the number of rows for Pascal’s Triangle.
7. Store the number of rows in rows.
13
8. Use a for loop to print each row.
9. For each row, use another for loop to print the correct binomial coefficients.
10. Calculate each coefficient using the formula (n! / (r!(n-r)!)).
11. Display the coefficients in the correct format to form the triangle.
12. Print the next row.
13. Repeat the process until all rows are printed.
14. End the program.
15. Close the scanner.
16. End the method.
17. End the class.
Source Code:
import [Link].*;
int n = [Link]();
int x=n,y=0,w=n,o=n-2;
[Link](" ");
14
}
x--;
[Link](k);
[Link](l);
y++;
[Link]();
[Link](" ");
[Link](s);
15
}
[Link](h);
[Link]();
w--; o--;}}}
Variable Description:
[Link] Variable Type Method Description
Output:
16
Result: Thus the program was successfully run without any error and the output is
verified.
STRING TOKENIZER
[Link]: 6
Date:
Aim: To write a java Source Code to print the number of words in a sentence and the
words with 4 letters (using StringTokenizer class. A StringTokenizer is used to break a string into
tokens, splitting the string by a specified delimiter).
Algorithm:
1. Start the program.
2. Import the StringTokenizer class.
3. Declare the class StringTokenizerExample.
4. Define the main() method.
5. Create a Scanner object for taking user input.
6. Prompt the user to enter a string.
17
7. Store the entered string in inputString.
8. Create a StringTokenizer object, passing the string and delimiter (e.g., space).
9. Use a while loop to check if there are tokens left in the StringTokenizer.
10. Inside the loop, print each token.
11. Repeat until all tokens are printed.
12. End the program.
13. Close the scanner.
14. End the method.
15. End the class.
Source Code:
import [Link].*;
String s = [Link]();
String s1;
[Link]();
while([Link]())
s1 = [Link]();
18
if([Link]()==4)
[Link](s1);
Variable Description:
[Link] Variable Type Method Description
19
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
Aim: To write a java Source Code to print the first letter of a word in a two or more
worded name (using StringTokenizer class).
Algorithm:
1. Start the program.
2. Import the Scanner class for user input.
3. Declare the class NameWithInitial.
4. Define the main() method.
20
5. Create a Scanner object to take user input.
6. Prompt the user to enter their full name.
7. Store the full name in fullName.
8. Split the fullName into an array of words.
9. For each word in the array, take the first letter and convert it to uppercase.
[Link] the first letter followed by a dot to the result string.
[Link] processing all words, print the result.
[Link] the program.
[Link] the scanner.
[Link] the method.
[Link] the class.
Source Code:
import [Link];
21
for (String word : words) {
[Link]([Link](0)).append(". ");
[Link]();
Variable Description:
Output:
22
Result: Thus the program was successfully run without any error and the output is
verified.
FREQUENCY OF PALINDROME
23
[Link]: 8
Date:
Aim:To write a java Source Code to print the number of palindrome words in a given
sentence (using StringTokenizer class).
Algorithm:
1. Start the program.
2. Import the Scanner class for taking input.
3. Declare the class PalindromeFrequency.
4. Define the main() method.
5. Create a Scanner object for reading input.
6. Prompt the user to enter the starting number of the range.
7. Store the starting number in start.
8. Prompt the user to enter the ending number of the range.
9. Store the ending number in end.
[Link] count to 0 to store the number of palindromes.
[Link] a for loop to check each number between start and end.
[Link] each number, check if it is a palindrome.
[Link] check for a palindrome, reverse the number and compare it with the original.
[Link] it’s a palindrome, increment count.
[Link] the loop, print the total count of palindromes.
[Link] the program.
[Link] the scanner.
[Link] the method.
[Link] the class.
24
Source Code:
import [Link].*;
String s = [Link]();
int count=0;
String rev="";
while([Link]())
String s2=[Link]();
rev="";
for(int i = 0;i<[Link]();i++)
char ch=[Link](i);
rev = ch+rev;
if([Link](s2))
count++;
25
}
Variable Description:
Output:
26
Result: Thus the program was successfully run without any error and the output is
verified.
MATRIX MULTIPLICATION
[Link]: 9
Date:
Aim: To write a java program to get the product of two matrix (Matrix Multiplication).
Algorithm:
1. Start the program.
2. Import the Scanner class for user input.
3. Declare the class MatrixMultiplication.
4. Define the main() method.
5. Create a Scanner object for input.
6. Prompt the user to enter the number of rows and columns for Matrix A.
7. Store the number of rows and columns in variables m1 and n1.
8. Prompt the user to enter the number of rows and columns for Matrix B.
27
9. Store the number of rows and columns in variables m2 and n2.
[Link] n1 != m2, print an error message and stop the program.
[Link] two 2D arrays A and B to store the matrices.
[Link] the user to enter the elements of Matrix A.
[Link] the Matrix A.
[Link] the user to enter the elements of Matrix B.
[Link] the Matrix B.
[Link] a 2D array C to store the result of the multiplication.
[Link] nested loops to multiply the matrices.
[Link] the result of multiplication in the corresponding positions of Matrix C.
[Link] the resultant matrix.
[Link] the program.
Source Code:
import [Link].*;
int m=[Link]();
int n=[Link]();
int p=[Link]();
int q=[Link]();
if(n==p)
28
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
arr1[i][j]=[Link]();
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
arr2[i][j]=[Link]();
for(int i=0;i<m;i++)
for(int j=0;j<q;j++)
{
29
arr3[i][j]=0;
for(int k=0;k<n;k++)
arr3[i][j]=arr3[i][j]+arr1[i][k]*arr2[k][j];
for(int i=0;i<m;i++)
for(int j=0;j<q;j++)
[Link](arr3[i][j]+" ");
[Link]();
else
30
Variable Description:
[Link] Variable Type Method Description
Output:
31
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
Aim: To write a java Source Code to get the ascending order of each row in an array.
32
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class EachRowAscending.
4. Define the main() method.
5. Create a Scanner object for taking input.
6. Prompt the user to enter the number of rows and columns for the matrix.
7. Store the dimensions in m and n.
8. Declare a 2D array matrix to store the matrix.
9. Prompt the user to enter the matrix elements.
[Link] the matrix.
[Link] a for loop to traverse each row.
[Link] each row using the [Link]() method.
[Link] the sorted rows.
[Link] the program.
[Link] the scanner.
[Link] the method.
[Link] the class.
Source Code:
import [Link].*;
33
int n = [Link]();
int m = [Link]();
int temp;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
A[i][j]=[Link]();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
for(int k=j+1;k<m;k++)
if(A[i][j]<A[i][k])
temp =A[i][j];
A[i][j]=A[i][k];
A[i][k]=temp;
34
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
[Link](A[i][j]+" ");
[Link]();
Variable Description:
35
4. A int main 1st array declaration.
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
36
DIAGONAL DIFFERENCE
[Link]: 11
Date:
Aim: To write a java Source Code to get the difference between the right and left
diagonal values in an array.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class DiagonalDifference.
4. Define the main() method.
5. Create a Scanner object to read user input.
6. Prompt the user to enter the size of the square matrix (n x n).
7. Store the size in n.
8. Declare a 2D array matrix of size n x n.
9. Prompt the user to enter the elements of the matrix.
[Link] the matrix with user input.
[Link] variables primarySum and secondarySum to 0.
[Link] a loop to traverse the primary diagonal (i = j).
[Link] each element in the primary diagonal, add its value to primarySum.
[Link] another loop to traverse the secondary diagonal (i + j = n-1).
[Link] each element in the secondary diagonal, add its value to secondarySum.
[Link] the absolute difference between primarySum and secondarySum.
37
[Link] the diagonal difference.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
int m=[Link]();
int n=[Link]();
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
arr[i][j]=[Link]();
38
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
for(int k=j;k<n-1;k++)
if(arr[i][j]>arr[i][k+1])
int temp=arr[i][k+1];
arr[i][k+1]=arr[i][j];
arr[i][j]=temp;
[Link]("Answer:");
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
[Link](arr[i][j]+" ");
}
39
[Link]();
} Variable Description:
Output:
40
Result: Thus the program was successfully run without any error and the output is
verified.
SUM OF DIGITIS
[Link]: 12
Date:
Aim: To write a java Source Code to get the sum of two digits using function or method.
Algorithm:
1. Create a separate function for addition process.
2. Get two elements in the main method.
3. Add the two digits in the addition function.
4. Call the Result sum value from the function to main method and print it.
41
Source Code:
import [Link].*;
int c=x+y;
return c;
int a=[Link]();
int b=[Link]();
Variable Description:
42
1. sc Scanner main Scanner class variable
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
Aim: To write a java Source Code to get the sum of two digits using function or method.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class PalindromeWithFunction.
4. Define the main() method.
5. Create a Scanner object for user input.
43
6. Prompt the user to enter a number.
7. Store the number in num.
8. Call the function isPalindrome() to check if the number is a palindrome.
9. If the function returns true, print that the number is a palindrome.
[Link] the function returns false, print that the number is not a palindrome.
[Link] the function isPalindrome() that checks if a number is a palindrome.
[Link] the function, reverse the number.
[Link] the reversed number with the original number.
[Link] true if they are equal, else return false.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link];
// Input a number
if (isPalindrome(num)) {
} else {
44
[Link](num + " is not a palindrome.");
}
[Link]();
while (num != 0) {
num /= 10;
Variable Description:
45
Variable Name Type Description
sc Scanner To take user input.
num int Stores the number entered by the user.
original int Stores the original number to compare with the reversed number.
reversed int Stores the reversed number.
digit int Stores each digit while reversing the number.
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
46
Aim: To write a java Source Code to get the number of words and blank spaces in a
sentence using function or method.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class FrequencyOfWordsAndSpaces.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a string.
7. Store the string in str.
8. Initialize variables wordCount and spaceCount to 0.
9. Split the string into words using split(" ").
[Link] the number of words using split() method.
[Link] over the words and increment wordCount for each word.
[Link] over the string and increment spaceCount for each blank space.
[Link] the word count and space count.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
String str,rev="";
void input()
47
[Link]("Enter the sentence : ");
str = [Link]();
void process()
for(int i=0;i<[Link]();i++)
rev=[Link](i)+rev;
void find()
int c=0;
for(int i=0;i<[Link]();i++)
char ch=[Link](i);
if(ch==' ')
c++;
[Link]();
[Link]();
[Link]();
Variable Description:
[Link] Variable Type Method Description
Output:
49
Result: Thus the program was successfully run without any error and the output is
verified.
RECURTION FACTORIAL
[Link]
Date:
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class RecursionFactorial.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a number.
7. Store the number in num.
8. Call the factorial() function.
9. The function will return the factorial of the number.
[Link] the number is 0 or 1, return 1.
[Link], return num * factorial(num - 1).
[Link] the factorial result.
50
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import java .util.*;
int fact(int x)
if(x==1)
return 1;
else
return x*fact(x-1);
int a ,b;
a=[Link]();
b=[Link](a);
51
[Link]("Factorial : "+b);
}Variable Description:
OUTPUT :
Result: Thus the program was successfully run without any error and the output is
verified.
52
RECURTION SUM OF DIGITS
[Link]
Date:
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class RecursionSumOfDigits.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a number.
7. Store the number in num.
8. Call the recursive function sumOfDigits().
9. In the function, if num is less than 10, return num.
[Link], return num % 10 + sumOfDigits(num / 10).
53
[Link] the result.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import java .util.*;
int sum(int x)
if(x==0)
return 0;
else
return x%10+sum(x/10);
int a=[Link]();
54
SodRecrsn obj =new SodRecrsn();
[Link]("Sum : "+[Link](a));
}Variable Description:
OUTPUT :
55
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
AIM: To get a number from user and to check whether the entered number is prime and
palindrome
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class PrimePalindromeUsingFunction.
4. Define the main() method.
5. Create a Scanner object for user input.
56
6. Prompt the user to enter a number.
7. Store the number in num.
8. Call the isPrime() function to check if the number is prime.
9. Call the isPalindrome() function to check if the number is a palindrome.
[Link] both conditions are true, print that the number is a prime palindrome.
[Link], print that the number is not a prime palindrome.
[Link] the function isPrime(), which checks if the number is prime.
[Link] the isPrime() function, use a loop to check if the number is divisible by any number
from 2 to num-1.
[Link] the function isPalindrome(), which checks if the number is a palindrome.
[Link] the isPalindrome() function, reverse the number and compare it to the original
number.
[Link] both conditions return true, print that it is a prime palindrome.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
[Link]("Enter a number");
int n=[Link]();
if(x==y&&x==true)
57
[Link]("Itz prime pali");
else
int c=0;
for(int i =1;i<=a;i++)
if (a%i==0)
c++;
if (c==2)
return true;
else
return false;
boolean ispaline(int a)
int b=a,rev=0;
58
while(a>0)
int digit=a%10;
rev=rev*10+digit;
a=a/10;
if (b==rev)
return true;
else
return false;
Variable Description:
[Link] Variable Type Method Description
OUTPUT :
59
Result: Thus the program was successfully run without any error and the output is
verified.
Sum of series
[Link]: 18
Date:
60
Aim: To find the Sum of the series.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class SumOfSeries.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter the number of terms in the series.
7. Store the number in n.
8. Initialize a variable sum to 0.
9. Use a loop to iterate through the terms.
[Link] the value of each term to sum.
[Link] example, if the series is squares of numbers, use the formula i^2.
[Link] the sum of the series.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source code:
import [Link].*;
class SumSrs_Function
double z=0;
double fact=1;
for(int i=1;i<=y;i++)
61
fact=fact*i;
z=z+([Link](x,i)/fact);
z=1+z;
return z;
double a=[Link]();
double n =[Link]();
}
Variable Description:
62
4 fact double Sum() Storable
Output:
Result:
Thus the program was successfully run without any error and the output is verified.
63
LINEAR SEARCH
[Link]: 19
Date:
AIM: To check whether the given array contains the number the user want and to print its
position .
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class LinearSearch.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter the size of the array.
7. Store the size in n.
8. Declare an array of size n.
9. Prompt the user to enter the elements of the array.
[Link] the elements in the array.
[Link] the user to enter the element to search for.
[Link] the element in target.
[Link] a loop to iterate through the array.
[Link] each element with the target element.
64
[Link] the element is found, print its index.
[Link] the element is not found, print a message.
[Link] the program.
[Link] the scanner.
Source Code:
int n =[Link]();
[Link]("enter elements");
int i,sum=0,c=0;
a[i]=[Link]();
int m = [Link]();
65
for(i = 0;i<n; i++)
if(m==a[i])
c=1;
break;
if(c==0)
Variable Description:
[Link] Variable Type Method Description
66
OUTPUT :
Result: Thus the program was successfully run without any error and the output is
verified.
Date:
Aim: To write a java Source Code to replace all the vowels in a sentence to “*”.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class ReplaceVowelsWithStars.
4. Define the main() method.
67
5. Create a Scanner object for user input.
6. Prompt the user to enter a string.
7. Store the string in str.
8. Initialize a new string result to an empty string.
9. Loop through each character of str.
[Link] if the character is a vowel (a, e, i, o, u).
[Link] the character is a vowel, append * to result.
[Link], append the character to result.
[Link] the modified string.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
String replace(String s)
for(int i=0;i<[Link]();i++)
char ch = [Link](i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||
ch=='U')
s=[Link](ch,'*');
return s;
68
}
[Link]([Link](str));
Variable Description:
[Link] Variable Type Method Description
Output:
69
Result: Thus the program was successfully run without any error and the output is
verified.
NUMBER IN WORDS
[Link]: 21
Date:
70
Aim: To write a java program to get a number and print it in word form.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class NumberInWords.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter a number.
7. Store the number in num.
8. Create arrays for unit, tens, and hundreds places.
9. Handle special cases for numbers below 20.
[Link] the number is less than 100, convert the tens and units place to words.
[Link] the number is greater than or equal to 100, break it down into hundreds, tens,
and units.
[Link] the words appropriately.
[Link] the number in words.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
71
[Link]("Enter number :");
int n =[Link]();
String w[]={"
","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twel
ve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty
","Thirty","Fourty"
,"Fifty","Sixty","Seventy","Eighty","Ninety"};
int c=4;
while(n!=0)
a[--c]=n%10;
n=n/10;
while(c!=0)
a[--c]=0;
if (a[0]!=0)
if (a[1]!=0)
if (a[2]!=0)
72
if (a[2]>=2)
[Link](""+w[a[2]+18]+"");
if (a[3]!=0)
[Link](""+w[a[3]]+"");
if (a[2]==1)
[Link](""+w[a[3]+10]+"");
else if ((a[2]==0)&&(a[3]!=0))
[Link](""+w[a[3]]+"");
Variable Description:
[Link] Variable Type Method Description
73
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
TIME IN WORDS
[Link]: 22
Date:
Aim: To write a java program to get the time and print it in word form.
Algorithm:
1. Start the program.
2. Import the Scanner class for input.
3. Declare the class TimeInWords.
4. Define the main() method.
5. Create a Scanner object for user input.
6. Prompt the user to enter the hours and minutes.
7. Store the hours and minutes in hours and minutes.
8. Convert hours and minutes to words using arrays.
9. Handle cases for "o'clock".
[Link] minutes is 0, print only the hours.
74
[Link] minutes is between 1 and 30, convert the minutes to words.
[Link] minutes are more than 30, subtract the minutes from 60 and adjust the hours
accordingly.
[Link] the hours and minutes in words.
[Link] the time in words.
[Link] the program.
[Link] the scanner.
[Link] the method and class.
Source Code:
import [Link].*;
int h =[Link]();
int m =[Link]();
String
w[]={"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twel
ve"};
String
y[]={"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twel
ve","thirteen","fourteen","fiften","seixteen","seventeen","eighteen","nineteen","twenty","t
75
wenty one","twenty two","twenty three","twenty four","twenty five","twenty six","twenty
seven","twenty eight","twenty nine"};
if(m == 0)
[Link](w[h]+"' O clock");
else if(m==15)
else if(m==30)
else if(m==45&&h==12)
[Link]("Quater to "+w[1]);
else if(m==45)
[Link]("Quater to"+w[h+1]);
76
if(m<30)
if(m>30&&h==12)
else if(m>30)
Variable Description:
77
4. a int Main() Array variable
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
[Link]
Date:
Algorithm:
78
1. Get a string from the user.
2. Store the string in a function.
3. Using recursion function reverse the string.
4. Check whether the reversed string is same as the original string.
5. If both the string are same then they are palindrome.
6. If both the string are not same then they are not palindrome.
7. Print the answer.
Source Code:
import [Link].*;
public class string_palin
{
String sent()
{
Scanner in=new Scanner ([Link]);
String a=[Link]();
return a;
}
public String rev(String a)
{
if ([Link]())
return a;
else
return rev([Link](1))+[Link](0);
}
public static void main(String args[])
{
string_palin obj = new string_palin();
String a=[Link]();
[Link](a);
String b =[Link](a);
[Link](b);
79
if ([Link](b))
Variable Description:
[Link] Variable Data type Method Description
1. in Scanner Main() Scanner class
variable
2. a String Main() String variable
3. b String Main() String variable
4. obj Function Main() Function object
Output:
80
Result: Thus the program was successfully run without any error and the output is
verified.
OVERLOADING
[Link]
Date:
Aim: To find the area of the square, rectangle and circle using overloading function
Algorithm:
1. Start the program.
2. Declare the class OverloadingExample.
3. Define the main() method.
81
4. Declare the first method add(int a, int b) to add two integers.
5. Declare the second method add(double a, double b) to add two doubles.
6. Declare the third method add(int a, int b, int c) to add three integers.
7. In the main() method, call each add method with appropriate arguments.
8. Print the results of each method call.
[Link] the program.
Source Code:
import [Link].*;
int area(int x)
return x*x;
return x*y;
double area(double x)
return 3.14*x*x;
}
82
public static void main (String args [])
double a=[Link](5.5);
double b=[Link](5,6);
double c=[Link](10);
}Variable Description:
Output:
83
Result: Thus the program was successfully run without any error and the output is
verified.
OVERRIDING
[Link]
Date:
84
Aim: To write a java program to perform Overriding.
Algorithm:
1. Start the program.
2. Declare the class Animal with a method sound().
3. Declare the subclass Dog which overrides the sound() method.
4. In the main() method, create an object of type Dog.
5. Call the sound() method using the Dog object.
6. The overridden method in Dog will be called.
7. End the program.
Source Code:
class ABC
int x=5;
void display()
[Link](x);
int x=4;
void display()
85
{
[Link](x);
void displace()
[Link]();
display();
Variable Description:
[Link] Variable Type Method Description
Output:
Result: Thus the program was successfully run without any error and the output is
verified
86
SELECTION SORT
[Link]
Date:
int n = [Link]();
87
int A[]=new int[n];
for(int i=0;i<n;i++)
A[i]=[Link]();
int temp;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(A[i]>A[j])
temp=A[i];
A[i]=A[j];
A[j]=temp;
[Link]();
for(int i=0;i<n;i++)
[Link](A[i]);
88
}}}
Variable Description:
[Link] Variable Type Method Description
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
BUBBLE SORT
[Link]
Date:
89
Aim: To write a java program to arrange array in ascending order using bubble sorting.
Algorithm:
1. Accept n as the size of the array.
2. Declare the array with n;
3. Repeat for i = 0,1,2,….n
4. Accept the elements of array in position i’s
5. Repeat for i = 0,1,2,3…n
6. Repeat for j = 0,1,2….n-1
7. if(A[j]>A[j+1])
8. if true then store the number in a temporary variable and exchange A[j] and A[j+1]
9. End loop
[Link] for i = 0,1,2…n
[Link] the altered array
Source Code:
import [Link].*;
int n = [Link]();
for(int i=0;i<n;i++)
90
{
A[i]=[Link]();
int temp;
for(int i=0;i<n;i++)
for(int j=0;j<n-1;j++)
if(A[j]>A[j+1])
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
[Link]();
for(int i=0;i<n;i++)
[Link](A[i]);
}}}
Variable Description:
91
[Link] Variable Type Method Description
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
BINARY SEARCH
[Link]
Date:
92
Aim: To write a java program to search an element in an array using binary search.
Algorithm:
1. Accept n as the size of the array.
2. Declare the array with n;
3. Repeat for i = 0,1,2,….n
4. Accept the elements of array in position i’s
5. Repeat for i = 0,1,2,3…n
6. Repeat for j = 0,1,2….n-1
7. if(A[j]>A[j+1])
8. if true then store the number in a temporary variable and exchange A[j] and A[j+1]
9. End loop
[Link] start=0 and end=n-1
[Link] key as the element to be searched
[Link](start<=end)
[Link] the average of start and end and store it in mid
[Link](A[mid]==key)
[Link] true then print that the element was found
[Link] check whether A[mid]<key
[Link] true then start=mid+1
[Link] end=mid-1
[Link] while loop
[Link](start>end)
[Link] that the element is not found
Source Code:
import [Link].*;
93
Scanner sc = new Scanner([Link]);
int n = [Link]();
for(int i=0;i<n;i++)
A[i]=[Link]();
int temp;
for(int i=0;i<n;i++)
for(int j=0;j<n-1;j++)
if(A[j]>A[j+1])
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}}}
int start=0;
int mid;
while(start<=end)
mid=(start+end)/2;
if(A[mid]==key)
break;
else if(A[mid]<key)
start=mid+1;
else
end=mid-1;
if(start>end)
[Link]("Not Found");}}}
Variable Description:
[Link] Variable Type Method Description
95
2. n int main Size of the array
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
KAPREKAR NUMBER
[Link]
Date:
96
Aim: To write a java program to check whether a given number is a kapricorn number or
not.
Algorithm:
1. Accept n as the input
2. Store the square of the input in m
3. while(m>0)
4. a=m%10
5. m=m/10
6. Find the number of digits in m by incrementing c++
7. Store 10^c/2
8. Using this separate the half from m
9. F=md%d
[Link]=md/d
[Link] md and and f and store it in sum
[Link](sum==n)
[Link] true then it is kapricorn
[Link] not kapricorn
Source Code:
import [Link].*;
97
int n = [Link]();
while(m>0)
a=m%10;
c++;
m=m/10;
int d=(int)[Link](10,c/2);
f=md%d;
md=md/d;
sum=sum+md+f;
if(sum==n)
[Link]("kapricorn ");
else
Variable Description:
98
1. n int main Input
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
FASCINATING NUMBER
[Link]: 30
Date:
99
Aim: To write a java program to check whether a given number is a Fascinating number
or not.
Algorithm:
1. Accept n as the input number
2. Repeat for i=1,2,3
3. p=n*i
4. Convert p into String s using force conversion
5. End loop
6. Repeat for i=1,2….10
7. Repeat for j=1,2,3…[Link]()
8. Separate the digits and store in ch
9. If(i==ch-48)
[Link]=md/d
[Link] true then c++
[Link] loop
[Link](c!=1)
[Link] true then flag=0
[Link]
[Link](flag==1)
[Link] true then Fascinating
[Link] not Fascinating
Source Code:
import [Link].*;
public class Fascinating_Number
100
{
public static void main (String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter The Number : ");
int n = [Link]();
int flag=1;
int p;String s="";int c=0;
for(int i=1;i<=3;i++)
{
p=n*i;
s=s+[Link](p);
}
for(int i=1;i<10;i++)
{
c=0;
for(int j=0;j<[Link]();j++)
{
char ch=[Link](j);
if(i==(ch-48))
{
c++;
}
}
101
if(c!=1)
{
flag=0;
break;
}
}
if(flag==1)
[Link](n+ " is a Fascinating Number");
else
[Link](n+" is not a Fascinating Number");
}
}
Variable Description:
102
Output:
Result: Thus the program was successfully run without any error and the output is
verified.
103
Bubble sort organizes an array in ascending order by comparing adjacent elements and swapping them if the first is greater than the second. This process repeats, effectively 'bubbling' larger elements to the end of the array. After each pass, the largest unsorted element is correctly positioned, and the process is repeated for the next unsorted portion, decrementing the range of unsorted elements by one each time. This is repeated until no more swaps are needed, indicating sorted order .
To verify if a number is a Special number, start by using the Scanner class to get user input and store the number in 'num'. Initialize 'sum' to store the sum of the factorials of digits. Extract each digit, calculate its factorial, and add it to 'sum'. If, after processing all digits, 'sum' equals the original number, it is a Special number. If not, it is not. Close the scanner once the check is complete .
To arrange each row of a matrix in ascending order in Java, first, define rows and columns using the Scanner class. Declare a 2D array for the matrix and input its elements. Use an outer loop to iterate over each row, applying Arrays.sort() to sort elements within that row. After row-wise sorting, print each sorted row. This approach ensures each row independently achieves ascending order .
To reverse a number and check if it is a palindrome, start by creating a Scanner object to take input. Store the original number in 'num' and another variable 'temp'. Initialize 'reverse' to zero. Extract each digit using modulus 10, build the reverse number by multiplying the current reverse number by 10 and adding the digit. Repeat until the number is zero. After reversing, if 'reverse' is equal to 'temp', then the number is a palindrome. Close the scanner at the end .
The linear search algorithm involves traversing each element of an array sequentially to find a target element, stopping when the element is found or all have been checked. Compared to binary search, linear search is less efficient as it requires checking every element in the worst case, making it O(n) in time complexity. In contrast, binary search systematically halves the search space each step, with O(log n) complexity, but requires a sorted array to function .
Binary search involves starting with a sorted array. Accept the size of the array and populate it. Define 'start' and 'end' variables as the indices of the first and last elements. While 'start' is less than or equal to 'end', calculate 'mid' as the average of 'start' and 'end'. If the mid-element equals the key, the search is successful. If the mid-element is less, update 'start' to 'mid + 1', otherwise set 'end' to 'mid - 1'. If 'start' exceeds 'end', the element is not found .
To determine if a number is a Pronic number, create a Scanner object for input and store the number in 'num'. Initialize a variable 'i' to 0 and use a while loop to check if 'i * (i + 1)' is less than or equal to 'num'. If 'i * (i + 1)' equals 'num', it is a Pronic number. If no such integer is found, the number is not a Pronic number. End the program and close the scanner .
Matrix multiplication in Java involves multiple steps. Start by determining if the number of columns in the first matrix matches the number of rows in the second matrix, as multiplication requires it. Declare two 2D arrays for these matrices and a third for the result. Input elements for both matrices. Use nested loops to compute the product, iterating over rows and columns and accumulating the sum of products of corresponding elements, placing in the result matrix. Print the result matrix, ensuring the program handles the case where matrices can't be multiplied by issuing an error message .
The algorithm to check if a number is an Armstrong number involves several steps: start by importing the Scanner class for input, declare the ArmstrongNumber class and define the main method. Create a Scanner object to take user input and store the entered number in a variable 'num'. Store the original number in 'temp'. Initialize 'sum' to zero for the sum of powers. Find the number of digits 'n'. Extract each digit, calculate its n-th power, and add to 'sum'. If 'sum' equals the original number, it is an Armstrong number. Otherwise, it is not. End the program and close the scanner .
To replace vowels in a sentence with asterisks in Java, start by reading the input string. Convert it into an array of characters or loop through the string. For each character, check if it's a vowel using a conditional statement. If the character is a vowel, replace it with '*'. Build a new string with non-vowel characters remaining unchanged or directly modify the original string. Output the resulting string with vowels replaced by asterisks .