0% found this document useful (0 votes)
70 views103 pages

ISC Computer 30 Programs 2025-2026

The document outlines several Java programs aimed at checking different types of numbers, including Armstrong, Palindrome, Pronic, Special numbers, and generating Pascal's Triangle. Each section includes the aim, algorithm, source code, variable descriptions, and results of the program execution. Additionally, there is a program for counting words in a sentence and identifying four-letter words using the StringTokenizer class.

Uploaded by

Varundarian
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views103 pages

ISC Computer 30 Programs 2025-2026

The document outlines several Java programs aimed at checking different types of numbers, including Armstrong, Palindrome, Pronic, Special numbers, and generating Pascal's Triangle. Each section includes the aim, algorithm, source code, variable descriptions, and results of the program execution. Additionally, there is a program for counting words in a sentence and identifying four-letter words using the StringTokenizer class.

Uploaded by

Varundarian
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ARMSTRONG NUMBER

[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 {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

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

int num = [Link]();

int temp = num;

int sum = 0;

int n = 0;

// Find the number of digits in the number

while (temp != 0) {

temp /= 10;

n++;

temp = num; // Reassign the original value of num to temp for calculation

while (temp != 0) {

int digit = temp % 10;

sum += [Link](digit, n); // Add the nth power of the digit

temp /= 10;

// Check if the number is Armstrong

if (sum == num) {

[Link](num + " is an Armstrong Number.");

} else {

2
[Link](num + " is not an Armstrong Number.");

[Link]();

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner Main Scanner class variable

2. n int Main Storing the input from


the user.

3. m int Main To duplicate and store


the original value of n.

4. a int Main To store the digits


separated from n.

5. cube int Main To store the value of


cube of digits.

6. sum int Main To store the sum of all


cubes of all digits.

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];

public class PalindromeNumber {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

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

int num = [Link]();

int temp = num;

int reverse = 0;

// Reverse the number

while (num != 0) {

int digit = num % 10;

reverse = reverse * 10 + digit;

5
num /= 10;

// Check if the number is Palindrome

if (reverse == temp) {

[Link](temp + " is a Palindrome Number.");

} else {

[Link](temp + " is not a Palindrome Number.");

[Link]();

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner Main Scanner class variable

2. n int Main Storing the input from


the user.

3. m int Main To duplicate and store


the original value of n.

4. a int Main To store the digits


separated from n.

5. rev int Main To store the reverse


value of the original
6
number.

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].*;

public class Pronic

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter Any Number");

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

[Link]("Not A Pronic Number");

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. n int main Storing the input from


the user.

3. c int main To check whether the if


loop is true or not.

4. i int main For loop variable.

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].*;

public class Special_Number

public static void main (String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter Any Number : ");

int n = [Link]();

int m = n ;

int a,sum=0;

for( ; n>0 ;)

a = n%10;

int fact=1;

for(int i=1 ; i<=a ; i++ )

11
{

fact = fact*i;

sum=sum+fact;

n=n/10;

if(sum == m)

[Link]("Special Number");

else

[Link]("Not a Special Number");

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. n int main Storing the input from


the user.

3. m int main To duplicate and store


the original value of n.

4. a int main To store the digits


separated from n.

5. fact int main To store the factorial


values.

6. sum int main To store the sum of


12
factorial values.

Output:

Result: Thus the program was successfully run without any error and the Output is
verified.

PASCAL’S TRIANGLE
[Link]::5

Date:

Aim: To write a java Source Code to create Pascal’s Triangle Pattern.

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].*;

public class patterndiamond

public static void main (String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter Any Number : ");

int n = [Link]();

int x=n,y=0,w=n,o=n-2;

for(int i=1 ; i<=n ; i++)

for(int j=1 ; j<=x ; j++)

[Link](" ");

14
}

x--;

for(int k=1 ; k<=i ; k++)

[Link](k);

for(int l=y ; l>=1; l--)

[Link](l);

y++;

[Link]();

for(int q=1 ; q<=n ; q++)

for(int e=1 ; e<=q+1 ; e++)

[Link](" ");

for(int s=1 ; s<w ; s++)

[Link](s);

15
}

for (int h=o;h>=1;h--)

[Link](h);

[Link]();

w--; o--;}}}

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. n int main Storing the input from


the user.

3. x int main To duplicate and store


the original value of n.

4. y int main To store zero value

5. i int main For loop variable for


rows.

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].*;

public class string

public static void main (String args[])

Scanner sc = new Scanner ([Link]);

[Link]("Enter the sentence");

String s = [Link]();

String s1;

StringTokenizer st = new StringTokenizer(s);

[Link]("Number of Words : " +[Link]());

[Link]();

[Link]("Words With 4 letters : ");

while([Link]())

s1 = [Link]();

18
if([Link]()==4)

[Link](s1);

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. s String main Storing the input from


the user.

3. s1 String main To separate the words


from the input sentence
and store it.

4. st Object StringTokenize StringTokenizer Class


r Variable

19
Output:

Result: Thus the program was successfully run without any error and the output is
verified.

NAME WITH INITIAL


[Link]: 7

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];

public class NameWithInitial {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter your full name: ");

String fullName = [Link]();

// Split the full name into words

String[] words = [Link](" ");

StringBuilder initials = new StringBuilder();

// Loop through each word and take the first letter

21
for (String word : words) {

[Link]([Link](0)).append(". ");

[Link]("Name with initials: " + [Link]().trim());

[Link]();

Variable Description:

[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. s String main Input Variable.

3. st object StringTokenize StringTokenizer


r Variable.

4. n int main To store the number of


words in the input.

5. i int main For loop variable.

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].*;

public class Palindrome_Freq

public static void main (String args[])

Scanner sc = new Scanner ([Link]);

[Link]("Enter the sentence");

String s = [Link]();

int count=0;

String rev="";

StringTokenizer st=new StringTokenizer(s);

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
}

[Link]("No. of palindrome words : " +count);

Variable Description:

[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. s String main Input Variable.

3. st object StringTokenize StringTokenizer


r Variable.

4. s2 String main Separate the words.

5. rev String main Reverse of every


words.

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].*;

public class MuLtIMaTrIxX

public static void main(String args[])

Scanner in=new Scanner ([Link]);

[Link]("Enter size of 1st mat");

int m=[Link]();

int n=[Link]();

[Link]("Enter Size of 2nd mat");

int p=[Link]();

int q=[Link]();

if(n==p)
28
{

int arr1[][]=new int[m][n];

int arr2[][]=new int[p][q];

int arr3[][]=new int[m][q];

[Link]("Enter all elements");

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

[Link]("Multiplication not possible ");

30
Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. n int main 1st array row.

3. m int main 1st array column.

4. A int main 1st array declaration.

5. p int main 2nd array row.

Output:

31
Result: Thus the program was successfully run without any error and the output is
verified.

EACH ROW ASCENDING


[Link]: 10

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].*;

public class Row_Ascending

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter The size of rows and columns :");

33
int n = [Link]();

int m = [Link]();

int temp;

int A[][]=new int[n][m];

[Link]("Enter array elements");

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:

[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. n int main 1st array row.

3. m int main 1st array column.

35
4. A int main 1st array declaration.

5. i int main For loop variable.

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].*;

public class Multrxxx_Asc

public static void main(String args[])

Scanner sc=new Scanner([Link]);

[Link]("Enter array size");

int m=[Link]();

int n=[Link]();

int arr[][]=new int[m][n];

[Link]("Enter array elements");

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:

Variable Type Description


Name
sc Scanne Used to take input from the user.
r
n int The size of the square matrix.
matrix int[][] 2D array to store the matrix elements.
primarySum int Stores the sum of the primary diagonal elements.
secondarySum int Stores the sum of the secondary diagonal elements.
diagonalDifference int Stores the absolute difference between the primary and secondary
diagonal sums.

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].*;

public class Sum_function

public int sum(int x,int y)

int c=x+y;

return c;

public static void main(String args[])

Scanner sc=new Scanner([Link]);

Sum_function obj =new Sum_function();

[Link]("Enter the Numbers : ");

int a=[Link]();

int b=[Link]();

[Link](" Sum : " +([Link](a,b)));

Variable Description:

[Link] Variable Type Method Description

42
1. sc Scanner main Scanner class variable

2. a int main Input variable.

3. b int main Input variable.

4. x int sum Function Variable.

Output:

Result: Thus the program was successfully run without any error and the output is
verified.

PALINDROME WITH FUNCTION


[Link]: 13

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];

public class PalindromeWithFunction {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

// Input a number

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

int num = [Link]();

// Check if the number is a palindrome

if (isPalindrome(num)) {

[Link](num + " is a palindrome.");

} else {

44
[Link](num + " is not a palindrome.");
}

[Link]();

// Function to check if a number is a palindrome

public static boolean isPalindrome(int num) {

int original = num, reversed = 0, digit;

// Reverse the number

while (num != 0) {

digit = num % 10;

reversed = reversed * 10 + digit;

num /= 10;

// Return true if the original and reversed numbers are equal

return original == reversed;


}

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.

FREQUENCY OF WORDS AND BLANK SPACES


[Link]: 14

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].*;

public class StringOP

String str,rev="";

void input()

Scanner sc=new Scanner ([Link]);

47
[Link]("Enter the sentence : ");

str = [Link]();

void process()

for(int i=0;i<[Link]();i++)

rev=[Link](i)+rev;

[Link]("Reverse : " +rev);

void find()

StringTokenizer st=new StringTokenizer(str);

[Link]("Number Of Words : " +[Link]());

int c=0;

for(int i=0;i<[Link]();i++)

char ch=[Link](i);

if(ch==' ')

c++;

[Link]("Number of blank spaces : "+c);


48
}

public static void main(String args[])

StringOP obj = new StringOP();

[Link]();

[Link]();

[Link]();

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. str int main Input variable.

3. rev int palindrome Function variable

4. ch int palindrome Store Digits.

Output:

49
Result: Thus the program was successfully run without any error and the output is
verified.

RECURTION FACTORIAL
[Link]

Date:

AIM: To find the factorial of a given number by using recursion .

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.*;

public class factRecrsn

int fact(int x)

if(x==1)

return 1;

else

return x*fact(x-1);

public static void main(String args[])

Scanner in = new Scanner ([Link]);

int a ,b;

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

a=[Link]();

factRecrsn obj =new factRecrsn();

b=[Link](a);
51
[Link]("Factorial : "+b);

}Variable Description:

[Link] Variable Type Method Description

1. in Scanner main Scanner class variable

2. a int main Input variable.

3. x int fact Function variable

4. b int fact Store Digits.

OUTPUT :

Result: Thus the program was successfully run without any error and the output is
verified.

52
RECURTION SUM OF DIGITS
[Link]

Date:

AIM: To find the sum of digits of a given number using recursion .

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.*;

public class SodRecrsn

int sum(int x)

if(x==0)

return 0;

else

return x%10+sum(x/10);

public static void main(String args[])

Scanner in = new Scanner ([Link]);

[Link](" enter a number");

int a=[Link]();

54
SodRecrsn obj =new SodRecrsn();

[Link]("Sum : "+[Link](a));

}Variable Description:

[Link] Variable Type Method Description

1. in Scanner main Scanner class variable

2. a int main Input variable.

3. x int fact Function variable

4. bb int main to displays

OUTPUT :

55
Result: Thus the program was successfully run without any error and the output is
verified.

PRIME PALLINDROME USING FUNCTION


[Link]

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].*;

public class PrimPalin

public static void main (String args[])

Scanner sc=new Scanner([Link]);

[Link]("Enter a number");

int n=[Link]();

PrimPalin obj= new PrimPalin ();

boolean x = obj. isprime(n);

boolean y = obj. ispaline(n);

if(x==y&&x==true)

57
[Link]("Itz prime pali");

else

[Link]("Itz not prime pali");

boolean isprime (int a)

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

1. in Scanner main Scanner class variable

2. a int main Input variable.

3. cc int main to check palindrome

4. bb int main to check prime

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 Sum(double x, double y)

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;

public static void main(String args[])

Scanner sc=new Scanner([Link]);

SumSrs_Function obj = new SumSrs_Function();

[Link]("Enter the numbers");

double a=[Link]();

[Link]("Enter the limit");

double n =[Link]();

[Link]("The sum : "+[Link](a,n));

}
Variable Description:

[Link] Variable Data type Method Description

1. sc Scanner Main() Scanner variable

2. n int Main() Input variable

3. a double Main() Input variable

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:

import java .[Link];

public class linear_search

public static void main(String args[])

Scanner in=new Scanner([Link]);

[Link](" enter size of array ");

int n =[Link]();

[Link]("enter elements");

int a[]=new int [n];

int i,sum=0,c=0;

for(i = 0;i<n; i++)

a[i]=[Link]();

[Link]("enter the number to find ");

int m = [Link]();

65
for(i = 0;i<n; i++)

if(m==a[i])

[Link]("it is in the "+i+ "position");

c=1;

break;

if(c==0)

[Link]("it is not present in this array ");

Variable Description:
[Link] Variable Type Method Description

1. in Scanner main Scanner class variable

2. n int main Input variable.

3. a int main to get input as array

4. c int main to check it is present in


the array or not

66
OUTPUT :

Result: Thus the program was successfully run without any error and the output is
verified.

REPLACE VOWELS WITH STARS


[Link]: 20

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].*;

public class Star

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
}

public static void main (String args[])

Star obj=new Star();

Scanner sc = new Scanner([Link]);

[Link]("Enter The Sentence : ");

String str = [Link]();

[Link]([Link](str));

Variable Description:
[Link] Variable Type Method Description

1. sc Scanner main Scanner class variable

2. str String main Input variable.

3. s String main Function Variable.

4. ch char replace To separate the


characters.

5. i int main For loop variable.

6. obj Object main Object Variable.

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].*;

public class NoInWrd

public static void main (String args[])

Scanner sc = new Scanner([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 a[]=new int [4];

int c=4;

while(n!=0)

a[--c]=n%10;

n=n/10;

while(c!=0)

a[--c]=0;

if (a[0]!=0)

[Link](w[a[0]]+" Thousand ");

if (a[1]!=0)

[Link](w[a[1]]+" Hundred ");

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

1. sc Scanner main Scanner class variable

2. a int main Array declaration.

3. word String main Function Variable.

4. n int main Input variable.

5. n1 int main Duplicate of input.

6. i int main Counter Variable.

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].*;

public class ClockZtime

public static void main (String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter Hour :");

int h =[Link]();

[Link]("Enter minute :");

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)

[Link]("Quater past "+w[h]);

else if(m==30)

[Link]("Half past "+w[h]);

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)

[Link](y[m]+" Minutes past "+w[h]);

if(m>30&&h==12)

[Link](y[60-m]+" Minutes to "+w[1]);

else if(m>30)

[Link](y[60-m]+" Minutes to "+w[h+1]);

Variable Description:

[Link] variable Data type Method Variable


Description
1. in Scanner Main() Scanner class variable

2. n int Main() Input variable

3. m int Main() Input variable

77
4. a int Main() Array variable

Output:

Result: Thus the program was successfully run without any error and the output is
verified.

STRING PALINDROME USING RECURSION

[Link]

Date:

Aim: To check whether the string is palindrome or not.

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))

[Link] ("it is a palindrome");


else
[Link]("it is not a palindrome");
}
}

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].*;

public class OverLoadng

int area(int x)

return x*x;

int area (int x,int y)

return x*y;

double area(double x)

return 3.14*x*x;

}
82
public static void main (String args [])

OverLoadng obj=new OverLoadng ();

double a=[Link](5.5);

double b=[Link](5,6);

double c=[Link](10);

[Link]("Area of Square = "+c);

[Link]("Area of Circle = "+a);

[Link]("Area of Rectangle = "+b);

}Variable Description:

[Link] Variable Type Method Description

1. x Int, double abc Function variable

2. y int abc Function variable

3. x int abc Function variable

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);

class XYZ extends ABC

int x=4;

void display()
85
{

[Link](x);

void displace()

[Link]();

display();

Variable Description:
[Link] Variable Type Method Description

1. x int abc Function variable

Output:

Result: Thus the program was successfully run without any error and the output is
verified

86
SELECTION SORT
[Link]

Date:

Aim: To write a java program to arrange array in ascending order.


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 = i+1,i+2…n
7. if(A[i]>A[j])
8. if true then store the number in a temporary variable and exchange A[i] and A[j]
9. end loop
[Link] for i = 0,1,2…n
[Link] the altered array
Source Code:
import [Link].*;

public class Selection_Sorting

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter The size array :");

int n = [Link]();

87
int A[]=new int[n];

[Link]("Enter array elements");

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

1. n int main Size of array

2. A int main Array variable

3. i int main For Loop Variable

4. j int main For Loop Variable

5. temp int main Temporary Variable

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].*;

public class Bubble_Sorting

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter The size array :");

int n = [Link]();

int A[]=new int[n];

[Link]("Enter array elements");

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

1. n int main Size of array

2. A int main Array variable

3. i int main For Loop Variable

4. j int main For Loop Variable

5. temp int main Temporary Variable

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].*;

public class Binary_Search

public static void main(String args[])

93
Scanner sc = new Scanner([Link]);

[Link]("Enter The size array :");

int n = [Link]();

int A[]=new int[n];

[Link]("Enter array elements");

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 end = n-1;

[Link]("Enter the element to be searched : ");


94
int key=[Link]();

int mid;

while(start<=end)

mid=(start+end)/2;

if(A[mid]==key)

[Link]("Element found in " +mid+ " position");

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

1. sc Scanner main Scanner class variable

95
2. n int main Size of the array

3. A int main Array declaration.

4. i int main For loop variable

5. j int main For loop variable

6. temp int main Temporary variable

5. start int main Starting index

6. end int main Ending index

7. key int main Element to be searched

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].*;

public class kapricorn


{

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter The Number :");

97
int n = [Link]();

int m=n*n , c=0 , a , md=m , f , sum=0;

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

[Link]("Not kapricorn ");

Variable Description:

[Link] Variable Type Method Description

98
1. n int main Input

2. m int main Square of the input

3. c int main Increment variable

4. a int main Temporary variable

5. md int main Duplicate m

6. f int main Store half of m

7. sum int main Sum of the halfs

8. sc int main Scanner Class Variable

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:

[Link] Variable Type Method Description

1. sc int main Scanner Variable

2. n int main Input Variable

3. flag int main Flag variable

4. p int main Product of input and i

5. s String main Store p in String form

6. c int main Increment Variable

7. i int main For loop variable

8. j int main For loop variable

102
Output:

Result: Thus the program was successfully run without any error and the output is
verified.

103

Common questions

Powered by AI

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 .

You might also like