Computer Record Final 2025
Computer Record Final 2025
Date:8.3.24
Program 1
A program to read and check the number is Special Number
or not
Source Code:
import java.util.*;
public class Special
,
public static void main()
,
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
int sum=0,prod=1,t=n;
while(t>0)
,
sum+=t%10;
prod*=t%10;
t/=10;
-
if(n == sum + prod)
System.out.println("It is a special number");
else
System.out.println("It is not a special number");
-
-
Sample: 1
Input:
123
Output:
It is not a special number
Sample: 2
Input:
19
Output:
It is a special number
Variable Description
Variable Datatype Description
n Int Receive number
from scanner
t Int
sum Int To store sum
prod int To store product
Pattern Printing
Date:21.3.24
Program 2
A program to display the following pattern using nested for
Loop
&&&&&
&###&
&###&
&###&
&&&&&
Source code:
Sample: 1
Input:
Output:
&&&&&
&###&
&###&
&###&
&&&&&
Variable Description
Variable Datatype Description
i Int For loop
j int For loop
Sum of the Series
Date 25.3.24
Program 3
A program to read the values of x and n from the user.
Calculate and print the sum of the following series using
nested loop
Source Code:
import java.util.*;
public class Sum_Series
,
public static void main()
,
Scanner sc = new Scanner (System.in);
System.out.print("Enter value of n");
int n = sc.nextInt();
double sum =0,Tsum =0; int f;
for(int i =1;i<=n;i++)
, f=1; Tsum =0;
for(int j=1;j<=i;j++)
,
f*=j;
Tsum = sum +j;
-
sum+= Tsum/f;
-
System.out.print("The sum of the series:"+sum);
-
-
Sample: 1
Input:
Enter value of n
3
Output:
The sum of the series:5.166666666666667
Sample: 2
Input:
Enter value of n
2
Output:
The sum of the series:2.5
Variable Description
Variable Datatype Description
n Int Input
Source code:
import java.util.*;
public class Lucky
,
public static void main()
,
Scanner sc =new Scanner(System.in);
System.out.println("Enter a number");
int n =sc.nextInt();
intt,sum=0;
t=n;
while(t>=10)
,
sum=0;
while(t>0)
,
sum+=t%10;
t/=10;
-
t=sum;
switch(t)
,
case 1: System.out.println("It is a lucky number");
break;
default: System.out.println("It is not a lucky number");
-
-
-
Sample: 1
Input:
Enter a number
19
Output:
It is a lucky number
Sample: 2
Input:
Enter a number
123
Output:
It is not a lucky number
Variable Description
Variable Datatype Description
n Int Input
t Int Temporary value
sum int To store sum
Character and ASCII code
Date: 4.4.24
Program 5
Declare a Single Dimensional character array of size 10.
Display the character and its ASCII Code.
Source Code:
import java.util.*;
public class ASCII
,
public static void main()
,
Scanner sc = new Scanner (System.in);
char a*+ = new char *10+;
System.out.println("Enter 10 charectars");
for(int i =0; i<10;i++)
a*i+ = sc.next().charAt(0);
Sample: 2
Input:
Enter 10 characters
1234567890
Output:
-
-
Sample: 1
Input:
Output:
Variable Description
Variable Datatype Description
n Int Size of array
a*+ Long Array
i Int For loop
s Int Search number
c int Counter
Transpose of a square Matrix
Date: 26.4.24
Program 7
Declare a DDA integer array of size n x n. Display the original
matrix, and its transpose in a matrix form. Find the sum of
the border elements
Source Code:
import java.util.*;
System.out.println("");
-
System.out.println("Transpose form");
for(j=0;j<n;j++)
,
for(i=0;i<n;i++)
System.out.print(a*i+*j+);
System.out.println("");
-
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(i==0||j==0||i==n-1||j==n-1)
sum+=a*i+*j+;
System.out.println("Sum of the border elements ="+sum);
-
-
Sample: 1
Input:
Original Matrix
12
34
Transpose form
13
24
Original Matrix
123
456
789
Transpose form
147
258
369
Variable Description
Variable Datatype Description
n Int Dimension of the
square matrix.
a*+ Int Matrix entered by
the user.
i Int For loop
j Int For loop
sum int Sum of border
elements
Prime Fill
Date: 14.6.24
Program 8
Declare and define a method prime() which takes an integer,
returns Boolean depends on the given number is prime or
not
Source code:
return true;
-
public void main()
,
int a*+= new int *10+;
int c=0,b=100;
while(c<10)
,
if(prime(b))
,
a*c+=b;
c++;
-
b++;
-
for(int j=0;j<10;j++)
System.out.println(a*j+);
-
-
Sample: 1
Input:
No input required for this program
Output:
101
103
107
109
113
127
131
137
139
149
Variable Description
Variable Datatype Description
n Int Boolean value
i Int For loop
a*+ Int Array to store
prime numbers.
b Int Current number to
check if prime or
not.
c Int Counter for prime
numbers.
j int For loop
Leap Year
Date: 28.6.24
Program 9
Declare and define a static method which takes an integer
and returns Boolean result
Source Code;
import java.util.*;
public class LeapYear ,
if (y % 400 == 0) ,
return true;
- else ,
return false;
-
- else ,
return true;
-
- else ,
return false;
-
-
public static void main(String*+ args) ,
System.out.println("Enter a year");
int n = sc.nextInt();
if(check.isLeapYear(n))
Sample: 1
Input:
Enter a year
2000
Output:
It is a leap year
Sample: 2
Input:
Enter a year
1900
Output:
It is not a leap year
Variable Description
Variable Datatype Description
y Int Method for
checking
whether it’s a
leap year or not
n int Year entered
Method Overloading
Date: 5.7.24
Program 10
Define a overloaded method Number()
void Number(int num, int d) – To count and display the
frequency of a digit in a number
void Number(int n) – To find and display the sum of even
digits present in the number
void Number(char c, int n) – to print the character, in a
triangular format with n number of lines
Complete the main function as a menu driven program to
invoke the above methods
Source Code:
public class Method_overload
,
void Number(int n, int d)
,
int t=n,c=0;
while(t>0)
,
if(t%10==d)
c++;
t/=10;
-
System.out.println("Number "+n+" Frequency "+c);
-
void Number(int n)
,
int t=n,sum=0;
while(t>0)
,
if(t%2==0)
sum+=t%10;
t/=10;
-
System.out.println("The sum of even numbers is "+sum);
-
void Number(char c,int n)
,
inti,j;
for(i=0;i<=n;i++)
,
for(j=0;j<=i;j++)
System.out.print(c);
System.out.println();
-
-
Sample: 1
Input:
Number(234567);
Output:
Number(1233445555, 5);
Output:
Variable Description
Variable Datatype Description
n Int Input number to
analyze.
d Int Digit to find the
frequency of in the
number.
t Int Temporary number
used to process the
original number n
c Int Frequency of the
digit.
Sum Int Sum of even digits
of the number n
i Int For loop
j int For loop
Swapping of two numbers
Date: 12.7.24
Program 11
Swap_int is a overloaded function has the following
definition. Define the methods as given
void swap_int(int x,int y): swaps the two parametric variables
void swap_obj(swap x, swap y): swaps the two integers data
in an objects
Complete the main method which establish the concept of
call by value and call by reference
Source Code:
import java.util.Scanner;
class swap
,
int a;
public void main()
,
Scanner sc = new Scanner(System.in);
swap o1 = new swap();
swap o2 = new swap();
System.out.print("Enter the first number: ");
int x = sc.nextInt();
o1.a = x;
System.out.print("Enter the second number: ");
int y = sc.nextInt();
o2.a = y;
System.out.println("\n\n CALL by Value");
System.out.println("Before swapping in main():");
System.out.println("x = " + x + ", y = " + y);
swap_int(x, y);
System.out.println("After swapping in main() :");
System.out.println("x = " + x + ", y = " + y);
System.out.println("\n\n CALL by Reference");
System.out.println("Before swapping in main() : ");
System.out.println("x = " + o1.a + ", y = " + o2.a);
swap_obj(o1,o2);
System.out.println("After swapping in main() :");
System.out.println("x = " + o1.a + ", y = " + o2.a);
-
public void swap_int(int a, int b)
,
System.out.println("Values of x and y in Method before
swapping ");
System.out.println("x = " + a + ", y = " + b);
int temp = a;
a = b;
b = temp;
System.out.println("Values of x and y in Method after
swapping ");
System.out.println("x = " + a + ", y = " + b);
-
public void swap_obj(swap m, swap n)
,
System.out.println("Values of x and y in Method before
swapping ");
System.out.println(" x = " + m.a + ", y = " + n.a);
int temp = m.a;
m.a = n.a;
n.a = temp;
System.out.println("Values of x and y in Method after
swapping ");
System.out.println(" x = " + m.a + ", y = " + n.a);
-
-
Sample: 1
Input:
CALL by Value
Before swapping in main():
x = 10, y = 20
Values of x and y in Method before swapping
x = 10, y = 20
Values of x and y in Method after swapping
x = 20, y = 10
After swapping in main():
x = 10, y = 20
CALL by Reference
Before swapping in main():
x = 10, y = 20
Values of x and y in Method before swapping
x = 10, y = 20
Values of x and y in Method after swapping
x = 20, y = 10
After swapping in main():
x = 20, y = 10
Sample: 2
Input:
CALL by Value
Before swapping in main():
x = 5, y = 15
Values of x and y in Method before swapping
x = 5, y = 15
Values of x and y in Method after swapping
x = 15, y = 5
After swapping in main():
x = 5, y = 15
CALL by Reference
Before swapping in main():
x = 5, y = 15
Values of x and y in Method before swapping
x = 5, y = 15
Values of x and y in Method after swapping
x = 15, y = 5
After swapping in main():
x = 15, y = 5
Variable Description
Variable Datatype Description
a int Value before
swapping
x int First integer to be
swapped.
y int Second integer to
be swapped.
b int Value before
swapping
temp int Temporary variable
used for swapping.
Pure and Impure Methods
Date: 26.7.24
Program 12
Define the below Methods to apply the concept of pure and
impure methods
Pronic(),Selection()
Define the below methods to apply the concept of pure and
impure methods
Pronic() which takes a integer and returns boolean result true
if the number is Pronic, otherwise false. Pronic number is the
number which is the product of two consecutive integers)
ii. Selection() which takes a Character array and arranges the
elements in alphabetical order. Complete the main method as
a menu driven program to invoke the above methods. Read
the data and printing the output should be done in main
method.
Source Code:
importjava.util.*;
class Pure_Impure
,
booleanPronic(int n)
,
int i;
for(i=1;i<n;i++)
if(i*(i+1)==n)
,
return true;
-
return false;
-
Enter a number
6
It is a Pronic number
Enter size of array
5
Enter the characters
elant
Output:
It is a Pronic number
Enter size of array
5
Enter the characters
Before Arranging
e
l
a
n
t
After Arranging
a
e
l
n
t
Sample: 2
Input:
Enter a number
7
It is not a Pronic number
Enter size of array
4
Enter the characters
dcab
Output:
Source Code:
import java.util.*;
public class Rectangle
,
doublel,b,a,p;
void Input()
,
Scanner sc = new Scanner(System.in);
System.out.println("Enter length and breadth");
l= sc.nextDouble();
b= sc.nextDouble();
-
void Calc()
,
a=l*b;
p=2*(l+b);
-
void Output()
,
System.out.println("Lenght:"+l+" Breadth:"+b+" Area:"+a+"
Perimeter:"+p);
-
public void main()
,
Input();
Calc();
Output();
-
-
Sample: 1
Input:
Sample: 2
Input:
Source Code:
import java.util.*;
Input:
Car Type: AC
Kilometers Travelled: 10.0
Total Bill: 100.0
Sample: 2
Input:
-
Fibo()
,
start = 0;
end = 0;
-
Fibo(int p, int q)
,
start =p;
end =q;
-
int fibo(int n)
,
int a = 0, b= 1, c=1;
for(int i = 3;i<=n;i++)
,
c= a+b;
a= b;
b= c;
-
return c;
-
void display(),
for(int i = start; i<=end ; i++)
System.out.println(fibo(i) );
-
-
Sample: 1
Input:
1
1
2
3
5
Sample: 2
Input:
2
3
5
8
13
Variable Description
Variable Datatype Description
Start Int Stores the start
term for the
Fibonacci series
End Int Stores the end
term for the
Fibonacci series
p Int Temporary variable
for start term input
q Int Temporary variable
for end term input
a Int First number in
Fibonacci series
b Int Second number in
Fibonacci series
c Int Stores the current
Fibonacci number
i int For loop
Vowels and Consonant
Date: 29.8.24
Program 16
Write a program to input a word and count the number of
vowels and consonants present in it.
Source Code:
import java.util.*;
public class V_C
,
public static void main()
,
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word");
String S = sc.next(); int v =0,c=0;
int n = S.length(); char ch;
-
-
-
System.out.println("Number of vowels "+v);
System.out.println("Number of consonants "+c);
-
-
Sample: 1
Input:
Enter a word
Hello
Output:
Number of vowels 2
Number of consonants 3
Sample: 2
Input:
Enter a word
Programming
Output:
Number of vowels 3
Number of consonants 8
Variable Description
Variable Datatype Description
s String Input word
v Int Counts the number of
vowels
c Int Counts the number of
consonants
n Int Length
Ch Char Stores each character
i int For loop
Word Extraction
Date: 3.10.24
Program 17
Write a program to input a sentence and convert it into
uppercase. Count and display the total number of words
starts and ends with letter 'A'.
Source Code:
import java.util.*;
public class Word_Extraction
,
public static void main()
,
Scanner sc = new Scanner (System.in);
System.out.println(“Enter a Word”);
String S = sc.nextLine();
char ch= ‘1’; int c =0;
int n = S.length(); String temp =””;
int I; int word = 0;
for(I =0;i<n;i++)
,
ch= S.charAt(i);
if(ch == ‘a’ || ch== ‘A’)
word = 1;
if(Character.isWhitespace(ch))
if(S.charAt(i-1) == ‘a’ || S.charAt(i-1) == ‘A’ && word == 1)
c++;
else
word = 0;
if(i== n-1)
if(S.charAt(i) == ‘a’ || S.charAt(i) == ‘A’ && word == 1)
c++;
else
word = 0;
-
System.out.println(“Number of words starting and ending with a
is : “+c);
for(I =0;i<n;i++)
,
ch= S.charAt(i);
temp += Character.toUpperCase(ch);
-
System.out.println(“New Senstence is \n”+temp);
-
-
Sample: 1
Input:
Enter a Word
My name is Aditya
Output:
Sample: 2
Input:
Enter a Word
John Lennon is a musician
Output:
return temp;
-
-
Sample 1:
Input:
Sample 3:
Input:
import java.util.*;
public class String_Rearrange
,
public static void main()
,
Scanner sc = new Scanner(System.in);
System.out.println("Enter a large String");
String S = sc.next();
String temp= "";
int n = S.length(); char c;
for(int i =0;i<n;i++)
,
c= S.charAt(i);
if(Character.isLowerCase(c))
temp+=c;
-
for(int i =0;i<n;i++)
,
c= S.charAt(i);
if(!Character.isLetter (c))
temp+=c;
-
for(int i =0;i<n;i++)
,
c= S.charAt(i);
if(Character.isUpperCase(c))
temp+=c;
-
System.out.println("Arranged form is\n"+temp);
-
-
Sample 1
Input:
Variable Description
Variable Datatype Description
s String Stores the input
string entered by the
user.
temp String Stores the rearranged
string
n Int To store length
c Char To store character
i int For loop
Bubble Sort – String
Date: 22.10.24
Program 20
To input 'n' number of country names in a string array and its
corresponding ISD code in a integer data type array. Convert
the names into uppercase and arrange the names in a
descending order of alphabet and its ISD code using bubble
sort.
Source Code:
import java.util.Scanner;
class Countries_Bubble
,
public static void main()
,
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the value of n”);;
int n=sc.nextInt();;
String name*+=new String*n+;
int code*+=new int*n+;
System.out.println(“Enter the name of the country along with
the ISD code”);
for(int i=0;i<n;i++)
,
name*i+=sc.next();
code*i+=sc.nextInt();
-
for(int i=0;i<n;i++)
name*i+=name*i+.toUpperCase();
String a;
int b;
for (int I = 0; I < n; i++)
for (int j = I + 1; j < n; j++)
if (name*i+.compareTo(name*j+) < 0)
,
a=name*i+;
name*i+=name*j+;
name*j+=a;
b=code*i+;
code*i+=code*j+;
code*j+=b;
-
for(int i=0;i<n;i++)
System.out.println(“Name of country:”+name*i++”\t”+” ISD
code:”+code*i+);
-
-
Sample Input: