ICSE Class 10 Java Projects
ICSE Class 10 Java Projects
PROJECT 2024-25
CLASS: 10
SECTION: D
ROLL NUMBER: 5
PROGRAM 1:
Question:
Write a program to input three numbers and print their sum of cubes.
Ans:
import java.util.*;
class Sum_of_cubes
int num1=sc.nextInt();
int num2=sc.nextInt();
int num3=sc.nextInt();
int sum=(int)(Math.pow(num1,3)+Math.pow(num2,3)+Math.pow(num3,3));
PROGRAM 2
Question:
Write a program that computes the area and circumference of a circle of an accepted radius.Use 3.14
as the value of pi.
Ans:
import java.util.*;
class Circle
radius=sc.nextDouble();
circumference=2*3.14*radius; //circumference=2*pi*radius
area=3.14*radius*radius; //area=pi*radius*radius
} }
Variable Data type Use
radius double Store radius of circle
circumference double Store the value of circumference
area double Store the area of circle
Input-Output screen
Enter radius of circle
2.1
The radius of the circle is:2.1
It' s circumference is:13.188
It's area is:13.8474
=======================================================================
PROGRAM 3
Question:
Write a program to input the runs conceded by a bowler in 4 overs and compute his economy.
Ans:
import java.util.*;
class Economy_rate
int ov_1,ov_2,ov_3,ov_4;
double eco;
ov_1=sc.nextInt();
ov_2=sc.nextInt();
ov_3=sc.nextInt();
ov_4=sc.nextInt();
eco=(ov_1+ov_2+ov_3+ov_4)/4.0;
Input-Output screen
Enter runs conceded in first over
5
Enter runs conceded in second over
12
Enter runs conceded in third over
7
Enter runs conceded in last over
10
Economy rate of the bowler is:8.5
=======================================================================
Enter runs conceded in first over
3
Enter runs conceded in second over
17
Enter runs conceded in third over
4
Enter runs conceded in last over
9
Economy rate of the bowler is:8.25
PROGRAM 4
Question:
Write a program to accept an integer whether it is odd or even. Also check whether it is divisible by 3
or not.
Ans:
import java.util.*;
class Odd_even
int num;
System.out.println("Enter an integer");
num=sc.nextInt();
if(num%2==1) //Conditions
else
if(num%3==0)
else
Input-Output screen
Enter an integer
65
The number is:65
The number is odd
The number is not divisible by 3
=======================================================================
Enter an integer
36
The number is:36
The number is even
The number is divisible by 3
Ans:
import java.util.*;
class Largest {
int n1,n2,n3,largest;
n1=sc.nextInt();
n2=sc.nextInt();
n3=sc.nextInt();
largest=Math.max(largest,n3);
} }
Variable Data type Use
n1 int First number
n2 int Second number
n3 int Third number
largest int Store the largest number
Input-Output screen
Enter 1st number
5
Enter 2nd number
77
Enter 3rd number
91
The largest number is:91
=======================================================================
Enter 1st number
66
Enter 2nd number
78
Enter 3rd number
33
The largest number is:78
PROGRAM 6
Question:
Write a program to input three unequal numbers and display the second smallest number.
Ans:
import java.util.*;
class Smallest
int a,b,c;
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if((a<b)&&(a<c)) //Conditions
if (b<c)
else
if((b<c)&&(b<a))
if(c<a)
else
if((c<a)&&(c<b))
{
if(a<b)
else
} //Main closed
} //Class closed
Input-Output screen
Enter three numbers
65
41
98
The second smallest number is:65
=======================================================================
Enter three numbers
12
4
89
The second smallest number is:12
PROGRAM 7
Question:
Write a program to input three angles of a triangle and check whether a triangle is possible or not. If
possible then check whether it is an acute-angled triangle, right-angled or an obtuse-angled triangle
otherwise, display 'Triangle not possible'.
Ans:
import java.util.*;
class TriangleAngle1
int a1 = sc.nextInt();
int a2 = sc.nextInt();
int a3 = sc.nextInt();
if (Sum == 180 && a1 > 0 && a2 > 0 && a3 > 0) { //check for triangle
System.out.println("Acute-angled Triangle");
System.out.println("Right-angled Triangle");
else if(a1>90&&a1<180||a2>90&&a2<180||a3>90&&a3<180)
System.out.println("Obtuse-angled Triangle");
else {
System.out.println("Triangle not possible");
Input-Output screen
Enter first angle: 45
Enter second angle: 90
Enter third angle: 45
Right-angled Triangle
=======================================================================
Enter first angle: 31
Enter second angle: 29
Enter third angle: 120
Obtuse-angled Triangle
PROGRAM 8
Question:
Write a menu based program accepting 2 numbers and entering: -
Ans:
import java.util.*;
class calc {
int n1,n2,c;
n1=sc.nextInt();
n2=sc.nextInt();
System.out.println("Enter 1 for addition,2 for subtraction,3 for multiplication and 4 for division");
{ case 1:
int s=n1+n2;
break;
case 2:
int diff=n2-n1;
break;
case 3:
int pro=n1*n2;
break;
case 4:
double quo=n2/n1;
break;
default:
PROGRAM 9
Question:
Using the switch statement, write a menu driven program:
1. To check and display whether a number input by the user is a composite number or not.
A number is said to be composite, if it has one or more than one factors excluding 1 and the
number itself.
Example: 4, 6, 8, 9...
Ans:
import java.util.Scanner;
class Menu
switch (ch) {
case 1: //case1
int n = sc.nextInt();
int c = 0;
if (n % i == 0)
c++; }
if (c > 2)
System.out.println("Composite Number");
else
break;
case 2: //case2
int s = 10;
while (num != 0) {
if (d < s)
s = d;
num /= 10;
break;
default:
System.out.println("Wrong choice");
} } }
Input-Output screen
Type 1 for Composite Number
Type 2 for Smallest Digit
Enter your choice: 1
Enter Number: 71
Not a Composite Number
=======================================================================
Type 1 for Composite Number
Type 2 for Smallest Digit
Enter your choice: 2
Enter Number: 98106
Smallest digit is 0
PROGRAM 10
Question:
Write a program to accept a number and print its factorial.
Ans:
import java.util.*;
class Factorial
int n,i,f=1;
System.out.println("Enter a number");
n=sc.nextInt();
for(i=1;i<=n;i++){
f=f*i; //Factorial
}
}
Input-Output screen
Enter a number
7
The factorial of the number is:5040
=======================================================================
Enter a number
13
The factorial of the number is:1932053504
PROGRAM 11
Question:
Write a program to accept a number and check whether the given number is prime or not.
Ans:
import java.util.*;
class Prime
int num,i,flag=0;
System.out.println("Enter a number");
num=sc.nextInt();
for(i=2;i<=(int)num/2;i++)
if(num%i==0)
flag=1;
break;
else
Input-Output screen
Enter a number
19
The number is prime
=======================================================================
Enter a number
91
The number is not prime
PROGRAM 12
Question:
Write a program to accept a number and print the sum of its digits.
Ans:
import java.util.*;
class Sum_of_digi
int num,s=0;
System.out.println("Enter a number");
num=sc.nextInt();
while(num!=0)
{
num/=10;
Input-Output screen
Enter a number
227
The sum of the digits is:11
=======================================================================
Enter a number
777949
The sum of the digits is:43
PROGRAM 13
Question:
Design a class name ShowRoom with the following description:
Member methods:
ShowRoom() — default constructor to initialize data members
public static void input() — To input customer name, mobile number, cost
public static void calculate() — To calculate discount on the cost of purchased items, based on
following criteria
public static void display() — To display customer name, mobile number, amount to be paid after
discount.
Write a main method to create an object of the class and call the above member methods.
Ans:
import java.util.Scanner;
class ShowRoom
String name;
long mobno;
double cost;
double dis;
double amount;
ShowRoom()
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
name = sc.nextLine();
cost = sc.nextDouble();
int disPercent = 0;
disPercent = 5;
disPercent = 10;
disPercent = 15;
else
disPercent = 20;
obj.input();
obj.calculate();
obj.display();
}
Variable Data type Use
name String To store name
mobno long To store mobile number
cost int To input cost
dis int Calculate discount amount
disPercent int Percentage of discount
amount int Final amount
Input-Output screen
Enter customer name: Rajanya Basu
Enter customer mobile no: 8881929392
Enter cost:
27500
Customer Name: Rajanya Basu
Mobile Number: 8881929392
Amount after discount: 23375.0
=======================================================================
Enter customer name: Rahul Ghosh
Enter customer mobile no: 98716265355
Enter cost:
43000
Customer Name: Rahul Ghosh
Mobile Number: 98716265355
Amount after discount: 34400.0
PROGRAM 14
Question:
Define a class called ParkingLot with the following description:
Instance variables/data members:
int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking lot.
double bill — To store the bill amount.
Member Methods:
public static void input() — To input and store the vno and hours.
public static void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or
part thereof, and ₹1.50 for each additional hour or part thereof.
public static void display() — To display the detail.
Write a main() method to create an object of the class and call the above methods.
Ans:
import java.util.Scanner;
int vno;
int hours;
double bill;
vno = sc.nextInt();
hours = sc.nextInt();
if (hours <= 1)
bill = 3;
else
obj.input();
obj.calculate();
obj.display();
Input-Output screen
Enter vehicle number: 8456
Enter hours: 3
Vehicle number: 8456
Hours: 3
Bill: 6.0
=======================================================================
Enter vehicle number: 7932
Enter hours: 5
Vehicle number: 7932
Hours: 5
Bill: 9.0
PROGRAM 15
Question:
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, then display the message "Special two—digit number"
otherwise, display the message "Not a special two-digit number".
Ans:
import java.util.Scanner;
class Special_2digit
{
num /= 10;
sum += digit;
pro *= digit;
count++;
if (count != 2)
else
Input-Output screen
Enter a 2 digit number: 45
Not a special 2-digit number
=======================================================================
Enter a 2 digit number: 59
Special 2-digit number
PROGRAM 16
Question:
Design a class to overload a function sumSeries() as follows:
(i) public static void sumSeries(int n, double x): with one integer argument and one double argument
to find and display the sum of the series given below:
(ii) public static void sumSeries(int n): to find and display the sum of the following series:
s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×n)
Ans:
class Overload
{
double sum = 0;
double t = x / i;
if (i % 2 == 0)
sum -= t;
else
sum += t;
term *= i;
sum += term;
System.out.println("Sum=" + sum);
Input-Output screen
Sum = 9.49404761904762
=======================================================================
Sum=378011820620313
PROGRAM 17
Question:
Write a program to initialize the seven Wonders of the World along with their locations in two
different arrays. Search for a name of the country input by the user. If found, display the name of the
country along with its Wonder, otherwise display "Sorry not found!".
Seven Wonders:
CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA,
COLOSSEUM
Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Examples:
Country name: INDIA
Output: TAJ MAHAL
Ans:
import java.util.*;
class Wonders_of_world {
String c = sc.nextLine();
if (locations[i].equalsIgnoreCase(c)) {
break;
if (i == locations.length)
Input-Output screen
Enter country: Brazil
BRAZIL - CHRIST THE REDEEMER
=======================================================================
Enter country: India
INDIA – TAJMAHAL
=======================================================================
Enter country: France
Sorry Not Found!
=======================================================================
Enter country: Italy
ITALY – COLOSSEUM
PROGRAM 18
Question:
Write a program to input five words in an array. Arrange these words in descending order of
alphabets, using selection sort technique. Print the sorted array.
Ans:
import java.util.*;
class Selsort{
int n = a.length;
a[i] = sc.nextLine();
if (a[j].compareToIgnoreCase(a[pos]) < 0) {
pos = j;
String t = a[pos];
a[pos] = a[i];
a[i] = t;
System.out.println("Sorted Names:");
System.out.println(a[i]);
Input-Output screen
Enter 5 Names:
Rahul
Ravi
Ashwin
Meena
Pinandiksha
Sorted Names:
Ashwin
Meena
Pinandiksha
Rahul
Ravi
PROGRAM 19
Question:
Write a program to input 15 integer elements in an array and sort them in ascending order using the
bubble sort technique.
Ans:
import java.util.Scanner;
class BubbleSort
int n = 15;
//Bubble Sort
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
System.out.println("Sorted Array:");
Input-Output screen
Enter the elements of the array:
7
19
22
10
0
112
23
59
26
9
55
8
45
3
444
Sorted Array:
0 3 7 8 9 10 19 22 23 26 45 55 59 112 444
PROGRAM 20
Question:
Write a program to perform binary search on a list of integers given below, to search for an element
input by the user. If it is found display the element along with its position, otherwise display the
message "Search element not found".
Ans:
import java.util.*;
class Binsearch
int n,l,h,index,m;
int arr[] = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};
n = sc.nextInt();
while (l <= h) {
m = (l + h) / 2;
if (arr[m] < n)
l = m + 1;
else if (arr[m] > n)
h = m - 1;
else {
index = m;
break;
if (index == -1) {
else {
Input-Output screen
Enter number to search:
20
20 found at position 6
=======================================================================
Enter number to search:
31
Search element not found
Ans:
import java.util.*;
class Special_arr
arr[i][j] = sc.nextInt();
if (arr[i][j] % 2 == 0)
evenSum += arr[i][j];
else
oddSum += arr[i][j];
System.out.println("Special Array");
else
Input-Output screen
Enter the elements of 3 x 3 DDA:
5
5
5
3
4
2
4
2
6
Sum of even elements = 18
Sum of odd elements = 18
Special Array
PROGRAM 22
Question:
Define a class to accept a string and convert it into uppercase. Count and display the number of
vowels in it.
Ans:
import java.util.*;
class Vowels
str = str.toUpperCase();
int count = 0;
char ch = str.charAt(i);
count++;
Ans:
import java.util.*;
class SpecialPalindrome
str = str.toUpperCase();
isPalin = false;
break;
if (isPalin) {
System.out.println("Palindrome");
else {
System.out.println("Special");
else {
Input-Output screen
Enter a word: MALAYALAM
Palindrome
=======================================================================
Enter a word: COMIC
Special
PROGRAM 24
Question:
Write a program to accept a word and display its piglatin form.
Ans:
import java.util.*;
class PigLatin
word=word.toUpperCase();
String piglatin="";
int flag=0;
char ch = word.charAt(i);
if("AEIOU".indexOf(ch)>=0)
flag=1;
break;
if(flag == 0) {
}
Variable Data type Use
word String Input the word
len int Length of string
piglatin String Store piglatin word
flag int Counts the presence of any vowel
i int Loop control variable
ch char Character extraction
Input-Output screen
Enter word: London
LONDON in Piglatin format is ONDONLAY
=======================================================================
Enter word: Giraffe
GIRAFFE in Piglatin format is IRAFFEGAY
PROGRAM 25
Question:
Write a program to input a sentence and arrange each word of the string in alphabetical order.
Ans:
import java.util.Scanner;
class WordsSort
System.out.println("Enter a sentence:");
int wc = 0;
char ch;
wc++;
int index = 0;
ch = str.charAt(i);
else {
wordArr[index++] = word;
word = "";
String t = wordArr[j];
wordArr[j] = wordArr[j+1];
wordArr[j+1] = t;
Input-Output screen
Enter a sentence:
The day is beautiful
beautiful day is The
=======================================================================
Enter a sentence:
The sun is shining brightly
brightly is The shining sun