Couputer Project Class 10
Couputer Project Class 10
OUTPUT 1-
QUESTION 2-
Write a program to accept name and total marks of N number of
students in two
single subscript array name[] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
PROGRAM 2-
import java.util.Scanner; //importing a library class
class b
{ //start of a class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();
OUTPUT 2-
QUESTION 3-
Write a function fact(int n) to find the factorial of a number n.Include
a main class to
find the value of S where:
S = n! / (m!(n - m)!), where, n! = 1 x 2 x 3 x .......... x n
PROGRAM 3-
import java.util.Scanner;
class c
{ //start of a class
public long fact(int n) { //method with a paramter
long f = 1;
for (int i = 1; i <= n; i++) { // start of for loop
f *= i;
}
return f;
}
public static void main(String args[]) {
c obj = new c ();
Scanner in = new Scanner(System.in);
System.out.print("Enter m: ");
int m = in.nextInt(); //accepting the input
System.out.print("Enter l: ");
int l = in.nextInt();
OUTPUT 3-
QUESTION 4-
Write a program to input integer elements into an array of size 20 and
perform the
following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.
PROGRAM 4-
import java.util.Scanner; //importing a library class
class d
{ //start of the class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < 20; i++) {
arr[i] = in.nextInt();
}
int min = arr[0], max = arr[0], sum = 0; //initialising the
variables
for (int i = 0; i < arr.length; i++) {
if (arr[i] < min)
min = arr[i];
if (arr[i] > max)
max = arr[i];
sum += arr[i];
}
OUTPUT 4-
QUESTION 5-
Write a program to input and store roll numbers, names and marks in
3 subjects of n number students in five single dimensional array and
display the remark based on average marks as given below :
(The maximum marks in the subject are 100)
PROGRAM 5-
import java.util.Scanner; //to import a library function
class e
{ // start of a class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();
int rollNo[] = new int[n];
String name[] = new String[n];
int s1[] = new int[n]; //to form an array
int s2[] = new int[n];
int s3[] = new int[n];
double avg[] = new double[n];
for (int i = 0; i < n; i++) {
System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine()
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i]) / 3.0;
}
System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) { // start of a for loop
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}}
} //end of a class
VDT 5-
Variable Variable Type Description/ Purpose
rollNo int To store the roll no
name String To store the name
remark int To store the marks
s1 int To store an array
s2 int To store an array
s3 int To store an array
i int To initialise a for loop
OUTPUT 5-
QUESTION 6-
Write a program in Java to store 20 numbers (even and odd numbers)
in a Single Dimensional Array (SDA). Calculate and display the sum
of all even numbers and all odd numbers separately.
PROGRAM 6-
import java.util.Scanner; //importing a library function
class f
{ //start of a class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
int oddSum = 0, evenSum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) //if statement to find the value
evenSum += arr[i];
else
oddSum += arr[i];
}
System.out.println("Sum of Odd numbers = " + oddSum);
System.out.println("Sum of Even numbers = " + evenSum);
}
} //end of class
VDT 6-
Variable Data type Description/Purpose
arr int To store an array
i int To initialise the for loop
oddSum int To save the values and perform calculations
evenSum int To save the values and perform calculations
OUTPUT 6-
QUESTION 7-
Write a program by using a class with the following specifications:
Class name — Hcflcm
Data members/instance variables:
int a
int b
Member functions:
Hcflcm(int x, int y) — constructor to initialize a=x and b=y.
void calculate( ) — to find and print hcf and lcm of both the numbers.
PROGRAM 7-
import java.util.Scanner; //to import a library function
class g
{ //start of a class
int a;
int b;
g (int x, int y) {
a = x;
b = y;
}
public void calculate() { //start of a function
int x = a, y = b;
while (y != 0) {
int t = y;
y = x % y;
x = t;
}
int hcf = x;
int lcm = (a * b) / hcf;
System.out.println("HCF = " + hcf);
System.out.println("LCM = " + lcm);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int x = in.nextInt();
System.out.print("Enter second number: ");
int y = in.nextInt();
g obj = new g(x,y); //assigning the values
obj.calculate();
}} //end of a class
VDT 7-
Variable Data Type Description/Purpose
a int To store values
b int To store values
x int To store values and perform functions
y int To store values and perform functions
hcf int To store values and perform functions
lcm int To store values and perform functions
OUTPUT 7 –
QUESTION 8-
Write a program by using a class with the following specifications:
Class name — Calculate
Instance variables:
int num
int f
int rev
Member Methods:
Calculate(int n) — to initialize num with n, f and rev with 0 (zero)
int prime() — to return 1, if number is prime
int reverse() — to return reverse of the number
void display() — to check and print whether the number is a prime
palindrome or not.
PROGRAM 8-
import java.util.Scanner; //importing a library function
class Calculate
{ // start of a class
private int num;
private int f;
private int rev;
public Calculate(int n) {
num = n;
f = 0;
rev = 0;
}
public int prime() {
f = 1;
if (num == 0 || num == 1) // stating the if condition
f = 0;
else
for (int i = 2; i <= num / 2; i++) { //start of the for
loop
if (num % i == 0) {
f = 0;
break;
}
}
return f;
}
public int reverse() {
int t = num;
while (t != 0) {
int digit = t % 10;
rev = rev * 10 + digit;
t /= 10;
}
return rev;
}
public void display() {
if (f == 1 && rev == num)
System.out.println(num + " is prime palindrome");
else
System.out.println(num + " is not prime palindrome");
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int x = in.nextInt();
Calculate obj = new Calculate(x);
obj.prime();
obj.reverse();
obj.display(); }
} //end of class
VDT 8-
Variable Data Type Description/ Purpose
num int To store values and perform calculations
rev int To store values and perform calculations
i int To initialise the for loop
t int To store values and perform calculations
f int To act as a flag
digit int To store values and perform calculations
OUTPUT 8-
QUESTION 9-
An electronics shop has announced a special discount on the purchase
of Laptops as
given below:
Category Discount on Laptop
Up to ₹25,000 5.0%
₹25,001 - ₹50,000 7.5%
₹50,001 - ₹1,00,000 10.0%
More than ₹1,00,000 15.0%
Define a class Laptop described as follows:
Data members/instance variables:
1. name
2. price
3. discount
4. amt
Member Methods:
1. A parameterised constructor to initialize the data members
2. To accept the details (name of the customer and the price)
3. To compute the discount
4. To display the name, discount and amount to be paid after discount.
Write a main method to create an object of the class and call the
member methods.
PROGRAM 9-
import java.util.Scanner; //importing a library function
public class Laptop
{ //start of a class
private String name;
private int price;
private double dis;
private double amt;
VDT 9-
Variable Data type Description/Purpose
name String To store the name
price int To store a value and perform calculations
dis double To store a value and perform calculations
amt double To store a value and perform calculations
s String To store a value
p int To store a value and perform calculations
OUTPUT 9-
QUESTION 10-
A special two-digit number is such that when the sum of its digits is
added to the product of its digits, the result is equal to the original
two-digit number. Example:
Consider the number 59.
Sum of digits = 5 + 9=14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its
digits to the product of its digits. If the value is equal to the number
input, output the message “Special 2-digit number” otherwise, output
the message “Not a special 2-digit number”.
PROGRAM 10-
import java.util.*; //importing a java function
class j
{ //start of the class
int num, sum=0, pro=1, finalsum=0;
void accept ( )
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter any two-digit number:");
num = ob.nextInt();
}
void computer ( )
{
int digit, n = num;
while (num != 0) //start of wile loop
{
digit = num% 10;
sum = sum + digit;
pro = pro * digit;
num = num/10;
}
finalsum = sum + pro;
if (finalsum == n)
{
System.out.println("Special 2-digit number");
}
else
{
System.out.println("Not a special 2-digit number");
}
}
public static void main ( )
{
j obj = new j ( );
obj.accept ( ); //calling the function accept
obj.computer ( );
}
} //end of class
VDT 10-
Variable Data Type Description /Purpose
Sum int To store values and perform calculations
pro int To store values and perform calculations
finalsum int To store values and perform calculations
digit int To store values and perform calculations
n int To store values and perform calculations
OUTPUT 10-
QUESTION 11-
Design a class to overload a function area( ) as follows:
(i) double area (double a, double b, double c) with three double
arguments, returns the area of a scalene triangle using the formula:
area = where s=(a+b+c)/2
(ii) double area (int a, int b, int height) with three integer arguments,
returns the area of a trapezium using the formula:
area = 1/2 height (a + b)
(iii) double area (double diagonal 1, double diagonal 2) with two
double arguments, returns the area of a rhombus using the formula :
area = 1/2 (diagonal 1 x diagonal 2)
PROGRAM 11-
import java.util.Scanner; //import library function
class k //start of a class
{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
- double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result; // the output is returned
}
double area (int a, int b, int height) { //function overloading
double result = (1.0 / 2.0) * height * (a + b);
return result;
}
double area (double diagonal1, double diagonal2) {
double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;
}
} //end of class
VDT 11-
a double to enter side of the triangle
b double to enter side of the triangle
}
}
QUESTION 12-
Using the switch statement, write a menu driven program to calculate
the maturity amount of a Bank Deposit.
The user is given the following options :
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal (P), rate of interest(r) and time period
m years(n). Calculate and output the maturity amount (A) receivable
using the formula .For option (ii) accept Monthly Instalment (P), rate
of interest (r) and time period in months (n). Calculate and output the
maturity amount (A) receivable using the formula
For an incorrect option, an appropriate error message should be
displayed.
PROGRAM 12-
mport java.util.Scanner; //importing a scanner function
public class l
{ // start of the class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Term Deposit");
System.out.println("Type 2 for Recurring Deposit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
double p = 0.0, r = 0.0, a = 0.0; //initialise the variables
int n = 0;
case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;
default:
System.out.println("Invalid choice");
}
}
} //end of the class
OUTPUT 12-
QUESTION 13-
Write a program to accept the year of graduation from school as an
integer valuefrom, the user. Using the Binary Search technique on the
sorted array of integers given below.
Output the message “Record exists” If the value input is located in the
array. If not, output the message “Record does not exist”.{1982, 1987,
1993, 1996. 1999, 2003, 2006, 2007, 2009, 2010}
PROGRAM 13-
import java.util.Scanner; //import a library function
public class m
{ //start of class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007,
2009, 2010};
VDT 13-
Variable Data Type Description/Purpose
l int To store a value and
h int To store a value and perform calculations
idx int To store a value and perform calculatiosn
m int To store value and perform calculations
OUTPUT 13-
QUESTION 14-
Define a class named Fruit Juice with the following description:
Instance variables / data members :
int product_code — stores the product code number
String flavour — stores the flavour of the juice (E.g. orange, apple,
etc.)
String pack_type — stores the type of packaging (E.g. tetra-pack,
PET bottle, etc.)
int pack_size — stores package size (E.g. 200 ml, 400 ml, etc.)
int product_price — stores the price of the product
Member methods :
(i) FruitJuice() — Default constructor to initialize integer data
members to 0 and String data members to “ ”.
(ii) void input( ) — To input and store the product code, flavour, pack
type, pack
size and product price.
(iii) void discount( ) — To reduce the product price by 10.
(iv) void display() — To display the product code, flavour, pack type,
pack size and product price.
PROGRAM 14-
import java.util.Scanner; //import library function
public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}
public void input() { //initialising a method
Scanner in = new Scanner(System.in);
System.out.print("Enter Flavour: ");
flavour = in.nextLine();
System.out.print("Enter Pack Type: ");
pack_type = in.nextLine();
System.out.print("Enter Product Code: ");
product_code = in.nextInt();
System.out.print("Enter Pack Size: ");
pack_size = in.nextInt();
System.out.print("Enter Product Price: ");
product_price = in.nextInt();
}
public void discount() {
product_price -= 10;
}
public void display() {
System.out.println("Product Code: " + product_code);
System.out.println("Flavour: " + flavour); //printing the output
System.out.println("Pack Type: " + pack_type);
System.out.println("Pack Size: " + pack_size);
System.out.println("Product Price: " + product_price);
}
public static void main(String args[]) {
FruitJuice obj = new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
} //end of class
VDT 14-
Variable Data Type Description/Purpose
pack_type int To store the input
product_code int
flavour Int To store the input
pack_size int To store the input
product_price int To store the input
OUTPUT 14-
QUESTION 15-
The International Standard Book Number (ISBN) is a unique numeric book
identifier which is printed on every book. The ISBN is based upon a 10-digit
code. The ISBN is legal if:
1 × digit 1 + 2 × digit 2 + 3 × digit 3 + 4 × digit 4 + 5 × digit 5 + 6 × digit 6
+ 7 × digit 7 + 8 ×
digit 8 + 9 × digit 9 + 10 × digit 10 is divisible by 11.
Example : For an ISBN 1401601499
Sum = 1×1 + 2×4 +3×0 + 4×1 + 5×6 + 6×0 + 7×1 + 8×4 + 9×9 + 10×9 = 253
which is divisible by 11.
Write a program to :
(i) Input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, output the message, “Illegal ISBN” and
terminate the program.
(iii) If the number is 10-digit, extract the digits of the number and compute the
sum as explained above. If the sum is divisible by 11, output the message,
“Legal ISBN”. If the sum is not divisible by 11, output the message, “Illegal
ISBN”.
PROGRAM 15-
import java.util.Scanner; //importing a library function
public class o
{ //start of class
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the ISBN: ");
long isbn = in.nextLong();
if (count != 10) {
System.out.println("Illegal ISBN");
}
else if (sum % 11 == 0) {
System.out.println("Legal ISBN");
}
else {
System.out.println("Illegal ISBN");
}
} //end of main method
} //end of class
VDT 15-
Variable Data type Description/Purpose
sum int To store a value and perform calculatiosn
count int To store a value and perform calculations
m int To store a value and perform calculations
d int To store a value and perform calculations
isbn int To store a value and perform calculations
OUTPUT 15-
QUESTION 16-
A tech number has even number of digits. If the number is split in two
equal halves, then the square of sum of these halves is equal to the
number itself. Write a program to generate and print all four digits
tech numbers.
Example- Consider the number : 3025
Square of sum of the halves of 3025=(30+25) 2 = (55) 2=3025 is a
tech number.
PROGRAM 16-
public class p
{ //start of class
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) { //start of for loop
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf; //calculating the output
if (i == sum * sum)
System.out.println(i); //printing the output
}
}
} //end of class
VDT 16-
Variable Data Type Description/Purpose
i int To initialise for loop
secondHalf int To store a value and perform calculations
firstHalf int To store a value and perform calculations
sum int To store a value and perform calculations
OUTPUT 16-
QUESTION 17-
17. Design a class to overload a function series ( ) as follows :
(i) double series (double n) with one double argument and returns the
sum of the series,
(ii) double series (double a, double n) with two double arguments and
returns the sum of the series.
PROGRAM 17 –
public class q
{ //start of a class
double series(double n) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double term = 1.0 / i;
sum += term;
}
return sum;
}
VDT 17-
Variable Data Type Description/Purpose
i int To initiatlise a for loop
sum int To store a value and perform calculations
term int To store a value and perform calculations
x int To store a value and perform calculations
e int To store a value and perform calculations
m int To store a value and perform calculations
OUTPUT 17-
QUESTION 18-
Write a program to input 10 numbers into an integer array and
interchange the consecutive elements in it. That is, interchange a[0]
with a[1], a[2] with a[3], a[4] with a[5]…..
For example, if array contains
9 12 3 7 89 34 15 16 67 25
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
After interchange it should have the elements arranged as:
12 9 7 3 34 89 16 15 25 67
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
PROGRAM 18-
import java.util.*;
public class swaparray{//start of a class
VDT 18-
Variable Data Type Description/Purpose
OUTPUT 18-
QUESTION 19-
Design a class to overload a function polygon() as follows:-
(i) void polygon(int n, char ch) — with one integer argument and one
character type argument that draws a filled square of side n using the
character stored in ch.
(ii) void polygon(int x, int y) — with two integer arguments that
draws a filled rectangle of length x and breadth y, using the symbol
‘@’.
(iii) void polygon( ) — with no argument that draws a filled triangle
shown below.
PROGRAM 19-
public class s
{ //start of a class
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}
public void polygon(int x, int y) {
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print('@');
}
System.out.println();
}
}
public void polygon() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
public static void main(String args[]) {
s obj = new s();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
} //end of class
VDT 19-
Variable Data Type Description/Purpose
OUTPUT 19-
QUESTION 20-
Write a program to accept the names of 10 cities in a single
dimensional string array and their STD (Subscribers Trunk Dialling)
codes in another single dimensional integer array. Search for a name
of a city input by the user in the list. If found, display “Search
successful” and print the name of the city along with its STD code, or
else display the message “Search Unsuccessful, No such city in the
list”.
PROGRAM 20-
import java.util.Scanner;
public class t
{ //start of a class
public static void main(String args[]) {
final int SIZE = 10;
Scanner in = new Scanner(System.in);
String cities[] = new String[SIZE];
String stdCodes[] = new String[SIZE];
System.out.println("Enter " + SIZE +
" cities and their STD codes:");
int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}
OUTPUT 20-
QUESTION 21-
Define a class called mobike with the following description:
Instance variables /data members:
String bno — to store the bike’s number for eg(UP65AB1234)
int phno — to store the phone number of the customer
String name — to store the name of the customer
int days — to store the number of days the bike is taken on rent
int charge — to calculate and store the rental charge
Member methods:
void input() — to input and store the detail of the customer.
void compute() — to compute the rental charge.
The rent for a mobike is charged on the following basis:
First five days Rs. 500 per day.
Next five days Rs. 400 per day.
Rest of the days Rs. 200 per day.
void display() — to display the details in the following format:
PROGRAM 21-
import java.util.Scanner;
VDT 21-
Variable Data Type Description/Purpose
OUTPUT 21-
QUESTION 22-
Write a program in Java to accept 10 different city names in a SDA.
Arrange the names in ascending order using Bubble sort method and
display them.
Sample Input : Delhi, Bangalore, Agra, Mumbai, Calcutta
Sample Output: Agra, Bangalore, Calcutta, Delhi, Mumbai
PROGRAM 22 –
class u
{ //start of a class
public static void main(String args[])
{
int name[]={“Delhi”, “Bangalore”, ”Agra”, ”Mumbai”, “Calcutta”};
int i, j;
String temp;
for()
VDT 22-
Variable Data Type Description/Purpose
OUTPUT 22-
QUESTION 23-
Write a program to input a number and print whether the number is a
special number or not.
(A number is said to be a special number, if the sum of the factorial of
the digits of the number is same as the original number).
Example : 145 is a special number, because 1!+4!+5! = 1 + 24 + 120
= 145 (where ! stands for factorial of the number and the factorial
value of a number is the product of all integers from 1 to that number,
example 5! = 1*2*3*4*5 = 120).
PROGRAM 23-
VDT 23-
Variable Data Type Description/Purpose
OUTPUT 23-
QUESTION 24-
Write a program to accept a word and convert it into lowercase if it is
in uppercase, and display the new word by replacing only the vowels
with the character following it :
Example :
Sample Input : computer
Sample Output : cpmpvtfr
PROGRAM 24-
import java.util.Scanner;
public class w
{ //start of a class
if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {
}
else {
newStr = newStr + ch;
}
}
System.out.println(newStr);
}
}
VDT 24-
Variable Data Type Description/Purpose
OUTPUT 24-
QUESTION 25-
Design a class to overload a function compared as follows :
(a) void compare(int, int) — to compare two integer values and print
the greater of the two integers.
(b) void compare(char, char) — to compare the numeric value of two
characters and print the character with higher numeric value.
(c) void compare(String, String) — to compare the length of the two
strings and print the longer of the two.
PROGRAM 25-
import java.util.Scanner;
public class x
{ //start of a class
public void compare(int a, int b) {
if (a > b) {
System.out.println(a);
}
else {
System.out.println(b);
}
if (x > y) {
System.out.println(a);
}
else {
System.out.println(b);
}
VDT 25-
Variable Data Type Description/Purpose
OUTPUT 25-
QUESTION 26-
Write a program in Java to accept 5 elements is one SDA and 7
elements in another SDA. Find out the second smallest element within
the first SDA and the second largest element within the second SDA.
[ Hint : sorting is done through bubble sorting technique and return
the second smallest and the second largest element using methods]
PROGRAM 26-
VDT 26-
Variable Data Type Description/Purpose
OUTPUT 26-
QUESTION 27-
Write a program in Java to accept 10 elements in a SDA and print the
following:-
i. Number of duplicate elements present in the array.
ii. Frequency of each element present in the array.
PROGRAM 27-
import java.util.*;
public class
{ //start of a class
for(int i=0;i<arr.length;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(arr[i]==arr[j])
c++;
}
}
System.out.println("Number of duplicate element: "+c);
int [] fr = new int [arr.length];
int visited = -1;
for(int i = 0; i < arr.length; i++){
int count = 1;
for(int j = i+1; j < arr.length; j++){
_.nodds's profile picture
if(arr[i] == arr[j]){
count++;
//To avoid counting same element again
fr[j] = visited;
}
}
if(fr[i] != visited)
fr[i] = count;
}
System.out.println("---------------------------------------");
System.out.println(" Element | Frequency");
System.out.println("---------------------------------------");
for(int i = 0; i < fr.length; i++){
if(fr[i] != visited)
System.out.println(" " + arr[i] + " | " + fr[i]);
}
System.out.println("----------------------------------------");
}
}
VDT 27-
Variable Data Type Description/Purpose
OUTPUT 27-
QUESTION 28-
Write a program in Java to accept a number and verify whether it is an
Emirp number or not. [ Hint:-A number is called an emirp number if
we get another prime number on reversing the number itself. In other
words, an emirp number is a number that is prime forwards or
backward. It is also known as twisted prime numbers. For eg
79 is an Emirp number]
PROGRAM 28-
import java.util.Scanner;
if (c == 2) {
int t = num;
int revNum = 0;
while(t != 0) {
int digit = t % 10;
t /= 10;
revNum = revNum * 10 + digit;
}
int c2 = 0;
for (int i = 1; i <= revNum; i++) {
if (revNum % i == 0) {
c2++;
}
}
if (c2 == 2)
System.out.println("Emirp Number");
else
System.out.println("Not Emirp Number");
}
else
System.out.println("Not Emirp Number");
}
}
VDT 28-
Variable Data Type Description/Purpose
OUTPUT 28-
QUESTION 29-
PROGRAM 29-
VDT 29-
Variable Data Type Description/Purpose
OUTPUT 29-
QUESTION 30-
PROGRAM 30-
VDT 30-
Variable Data Type Description/Purpose
OUTPUT 30-