Computer Applications Lab Manual 2024-25
Computer Applications Lab Manual 2024-25
A.Y. 2024-25
ASSIGNMENT – 1
4. What is ‘Unicode’?
Ans: Unicode is a standard encoding system. It is a wide representation of
characters in numeric form.
A.Y. 2024-25
ASSIGNMENT – 2
Soln:
z= 21 + 30 - 21/2
z= 51-10
z=41
b) int p = 3, q= 8;
Soln:
r= 8 % 3 * 10 + 3
r = 2 * 10 + 3
r= 23
Soln:
d= 4 – (5 + 7 * 4 + 7/6 – 10)
d= 4 – (5 + 28 + 1 – 10)
d= 4 – 24
d= -20
d) int a=4, b=8, c=12, d=4;
Soln:
d=4/21
d=0
2. What is associativity?
Ans: When two operators have the same precedence, associativity determines
the evaluation order.
Associativity can be either left to right or right to left.
3. Distinguish between:
Ans:
Ans:
4. Give the capacity in bytes for the int and long data types.
Ans: int – 4 bytes, long – 8 bytes
Ans:
a) double d = 7.243
b) long a = 3112233
c) float f = 245.453f
d) boolean b =true
Ans:
Eg: int c =a + b;
Ans:
A.Y. 2024-25
ASSIGNMENT – 3
java.util.*
java.lang.*
java.io.*
Ans:
(write explanation)
Blue Ridge Public School
A.Y. 2024-25
ASSIGNMENT – 4
2. Math.ceil(5.1)
3. Math.max(Math.ceil(-3.7),-4))
4. Math.ceil(Math.abs(-8.6))
5. Math.pow(7,3)
6. Math.sqrt(Math.min(25,16))
7. Math.cbrt(Math.max(27,64))
8. Math.round(Math.abs(-12.2))
1. x(a+b)
2. (ab)/3
Ans:
A.Y. 2024-25
➢ Member Methods
• void accept(): To take input of name, coach, mobile number
and amount
• void update(): To update amount as per coach selected
Second_AC 500
Third_AC 250
sleeper none
Write the main method to create an object of the class and invoke the
member methods.
import java.util.*;
class RailwayTicket
{
String name, coach;
long mobno;
int amt, totalamt;
void accept()
{
void update()
{
if(coach.equalsIgnoreCase(“First_AC”)
{
totalamt = amt + 700;
}
else if(coach.equalsIgnoreCase(“Second_AC”)
{
totalamt = amt + 500;
}
else if(coach.equalsIgnoreCase(“Third_AC”)
{
totalamt = amt + 250;
}
else if(coach.equalsIgnoreCase(“sleeper”)
{
totalamt = amt;
}
else
{
System.out.println(“Invalid Coach”);
System.exit(0);
}
void display()
{
System.out.println(“Customer Name: ” +
name);
System.out.println(“Desired Coach: ” +
coach);
System.out.println(“Mobile Number: ” +
mobno);
System.out.println(“Total amount to be paid:
Rs.” + totalamt);
}//program terminates
OUTPUT
Enter Customer Name:
Aniruddh Mathur
Enter desired coach:
First_AC
Enter mobile number:
8888844444
Enter basic amount:
10000
Customer Name: Aniruddh Mathur
Desired Coach: First_AC
Mobile Number: 8888844444
Total amount to be paid: Rs.10700
A.Y. 2024-25
class Overload
{
//method to find the area of a scalene triangle
double area(double a, double b, double c)
{
double s = (a + b + c)/2;
double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
return area;
}//end of method
}//end of method
}//end of method
}//class ends
A.Y. 2024-25
A.Y. 2024-25
ASSIGNMENT – 8:
import java.util.*;
class Cyclo
{
void checkCyclo()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter a number:”);
int n = sc.nextInt();
if(first == last)
System.out.println(n + “ is a Cyclo
number”);
else
System.out.println(n + “ is not a
Cyclo number”);
}//end of method
}//class ends
OUTPUT
Enter a number:
704327
704327 is a Cyclo number
A.Y. 2024-25
ASSIGNMENT – 9
import java.util.*;
public class Nest
{
public void determineNest()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter a number: “);
int n = sc.nextInt();
int p = 1, tempnum = n;
while(tempnum != 0)
{
p = p * (tempnum % 10);
tempnum /= 10;
}
if(p == 0)
System.out.println(n + “ is a Nest number”);
else
System.out.println(n + “ is not a Nest number”);
}//closed the method
A.Y. 2024-25
ASSIGNMENT – 10
1 2 3
S= + + +……upto n terms
𝑎1 𝑎3 𝑎5
import java.util.*;
public class Series
{
public void sumSeries()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter number of terms: “);
int n = sc.nextInt();
System.out.println(“Enter the denominator value: “);
int a = sc.nextInt();
int j = 0; double sum = 0;
for(int i = 1; i <= n; i++)
{
j = 2 * i - 1;
sum += i/Math.pow(a,j);
}
System.out.println(“Sum of the series is: “ + sum);
A.Y. 2024-25
ASSIGNMENT – 11
import java.util.*;
public class ArrLinearSearch
{
String [] cityNames = new String[10];
int [] citySTD = new int[10];
String searchCity;
public void input()
{
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 10; i++)
{
System.out.print("Enter City Name: ");
cityNames[i] = sc.next();
System.out.print("Enter City STD Code: ");
citySTD[i] = sc.nextInt();
}
System.out.print("Enter name of the city to be
searched: ");
searchCity = sc.next();
}//end of input method
public void linearSearch()
{
boolean isFound = false;
int i = 0;
for(i=0; i < 10; i++)
{
if(cityNames[i].equalsIgnoreCase(searchCity))
{
isFound = true;
break;
}
}
if(isFound)
{
System.out.println("Search Successful");
System.out.println("City: " + cityNames[i]);
System.out.println("City STD Code: " +
citySTD[i]);
}
else
{
System.out.println("Search Unsuccessful, no such
city in the list");
}
} //end of search method
A.Y. 2024-25
ASSIGNMENT – 12
import java.util.*;
public class ArrDescBinarySearch
{
int [] arr;
int ns;
}
if(isFound){
System.out.println("Search Number " + ns
+ " found at position "
+ pos + " in the array");
}
else{
System.out.println("Search Number " + ns
+ " not found in the
array");
}
} //end of binary search method
public static void main(String [] args){
ArrDescBinarySearch obj = new ArrDescBinarySearch();
obj.input();
obj.binarySearch();
}//main method ends
}//program ends
OUTPUT
A.Y. 2024-25
ASSIGNMENT – 13
import java.util.*;
public class ArrDiagonalSum
{
int [][] arr = new int[3][3];
public void input2DArray()
{
Scanner sc = new Scanner (System.in);
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
System.out.print("Enter element " + i + ","
+ j + ": ");
arr[i][j] = sc.nextInt();
}
}
} //input method ends
public void print2DArray()
{
//print elements of the array in a matrix form
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
System.out.print(arr[i][j] + " ");
}
System.out.println();
}//end of for loop
} //print method ends
OUTPUT
A.Y. 2024-25
ASSIGNMENT – 14
import java.util.*;
public class StringArraySort
{
String [] name = new String[20];
public void input()
{
Scanner sc = new Scanner(System.in);
for(int i = 0; i < name.length; i++)
{
System.out.print("Enter a name: ");
name[i] = sc.next();
}
} //end of input method
A.Y. 2024-25
ASSIGNMENT – 15
A.Y. 2024-25
ASSIGNMENT – 16
import java.util.*;
public class StringUnique
{
public void checkUnique()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the word: ");
String str = sc.next();
str = str.toUpperCase();
char ch ;
int count = 0;
for(int i = 0; i < str.length(); i++)
{
for(int j = i+1; j < str.length(); j++)
{
if(str.charAt(i) == str.charAt(j))
count++;
}
}
if(count >= 1)
System.out.println("The word " + str + " is not
unique");
else
System.out.println("The word " + str + " is
unique");
}
public static void main(String [] args)
{
StringUnique obj = new StringUnique();
obj.checkUnique();
}
}
OUTPUT
A.Y. 2024-25
ASSIGNMENT – 17
1. Write a program to accept a sentence from the user and convert the
first character of every word to uppercase.
import java.util.*;
public class StringCaseChange
{
public void stringConvert(String s)
{
s = " " + s;
String cs = "";
char ch;
for(int i = 0; i < s.length(); i++)
{
ch = s.charAt(i);
if(Character.isWhitespace(ch))
{
ch = Character.toUpperCase(s.charAt(i+1));
if(i!= 0)
cs = cs + " " + ch;
else
cs = cs + ch;
i++;
}
else
cs += ch;
}
System.out.println("The original string is: " +
s.trim());
Enter a sentence:
We are in a cyber world
The original string is: We are in a cyber world
The converted string is: We Are In A Cyber World
A.Y. 2024-25
ASSIGNMENT – 18
1. Write a program to accept a sentence from the user and convert the
first character of every word to uppercase and also punctuate every
word with a dot.
import java.util.*;
public class StringCaseChange2
{
public void stringConvert(String s)
{
s = " " + s;
String cs = "";
char ch;
}
else if(Character.isWhitespace(ch))
{
ch = Character.toUpperCase(s.charAt(i+1));
cs = cs + "." + ch;
i++;
}
else
cs += ch;
}
System.out.println("The original string is: " +
s.trim());
Enter a sentence:
Welcome to java
The original string is: Welcome to java
The converted string is: Welcome.To.Java
A.Y. 2024-25
ASSIGNMENT – 19
1. Write a program to accept a sentence from the user and display only
the initials (i.e. first letter of each word) and punctuate every initial
with a dot.
import java.util.*;
public class StringInitials
{
public void stringConvert(String s)
{
s = " " + s;
String cs = "";
char ch;
}
public static void main(String [] args)
{
StringInitials obj = new StringInitials();
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence: ");
obj.stringConvert(sc.nextLine());
}
}
OUTPUT
Enter a sentence:
India is my country
The original string is: India is my country
The converted string is: I.i.m.c.
A.Y. 2024-25
ASSIGNMENT – 20
import java.util.*;
public class Frequency
{
public void findFrequency()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string: ");
String str = sc.nextLine();
str = str.toUpperCase();
int count = 0;
char ch1;
System.out.println("Char" + "\t" + "Frequency");
for(char ch = 'A'; ch <= 'Z'; ch++)
{
count = 0;
for(int j = 0; j < str.length() ; j++)
{
ch1 = str.charAt(j);
if(ch == ch1)
count++;
}
if(count != 0)
{
System.out.println(ch + "\t" + count);
}
}
}
public static void main(String [] args)
{
Frequency obj = new Frequency();
obj.findFrequency();
}
}
OUTPUT
Enter a string:
computer applications
Char Frequency
A 2
C 2
E 1
I 2
L 1
M 1
N 1
O 2
P 3
R 1
S 1
T 2
U 1
Variable Name Data type Description