Skip to content

25 Important Java Programs for ICSE and ISC

Here are 25 important Java programs for ICSE Class 10 and ISC Class 12. Students should practice these programs for their board examinations.

1. Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
(b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
import java.util.Scanner;

public class Program1
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 1 for letters and Unicode");
        System.out.println("Enter 2 to display the pattern");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        switch(ch) {
            case 1:
            System.out.println("Letters\tUnicode");
            for (int i = 65; i <= 90; i++)
                System.out.println((char)i + "\t" + i);
            break;
            
            case 2:
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= i; j++)
                    System.out.print(j + " ");
                System.out.println();
            }
            break;
            
            default:
            System.out.println("Wrong choice");
            break;
        }
    }
}
2. Design a class to overload a function series( ) as follows:
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ………. xn terms
(b) void series (int p) – To display the following series:
0, 7, 26, 63 ………. p terms
(c) void series () – To display the sum of the series given below:
1/2 + 1/3 + 1/4 + ………. 1/10
public class Program2
{
    void series(int x, int n) {
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += Math.pow(x, i);
        }
        System.out.println("Sum = " + sum);
    }

    void series(int p) {
        for (int i = 1; i <= p; i++) {
            int term = (int)(Math.pow(i, 3) - 1);
            System.out.print(term + " ");
        }
        System.out.println();
    }

    void series() {
        double sum = 0.0;
        for (int i = 2; i <= 10; i++) {
            sum += 1.0 / i;
        }
        System.out.println("Sum = " + sum);
    }
}
3. Write a program to input a number and check and print whether it is a Pronic number or not.
[Pronic number is the number which is the product of two consecutive integers.]
Examples:
12 = 3 * 4
20 = 4 * 5
42 = 6 * 7
import java.util.Scanner;

public class Program3
{
    public void pronicCheck() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number to check: ");
        int num = in.nextInt();
        
        boolean isPronic = false;
        
        for (int i = 1; i <= num - 1; i++) {
            if (i * (i + 1) == num) {
                isPronic = true;
                break;
            }
        }
        
        if (isPronic)
            System.out.println(num + " is a pronic number");
        else
            System.out.println(num + " is not a pronic number");
    }
}
4. Write a program to accept a number and check whether it is a ‘Spy Number’ or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: Sample Input: 1124
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8
import java.util.Scanner;

public class Program4
{
    public static void main(String[] args)  {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter Number: ");
        int num = in.nextInt();
        
        int digit, sum = 0;
        int orgNum = num;
        int prod = 1;
        
        while (num > 0) {
            digit = num % 10;
            
            sum += digit;
            prod *= digit;
            num /= 10;
        }
        
        if (sum == prod)
            System.out.println(orgNum + " is Spy Number");
        else
            System.out.println(orgNum + " is not Spy Number");
        
    }
}
5. Using switch statement, write a menu driven program for the following:
(a) To find and display the sum of the series given below:
S = x1 – x2 + x3 – x4 + x5 – ………… – x20; where x = 2
(b) To display the series:
1, 11, 111, 1111, 11111
For an incorrect option, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program5
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("1. Sum of the series");
        System.out.println("2. Display series");
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();

        switch (choice) {
            case 1:
            int sum = 0;
            for (int i = 1; i <= 20; i++) {
                int term = (int)Math.pow(2, i);
                if (i % 2 == 0)
                    sum -= term;
                else
                    sum += term;
            }
            System.out.println("Sum=" + sum);
            break;
            
            case 2:
            int term = 1;
            for (int i = 1; i <= 5; i++) {
                System.out.print(term + " ");
                term = term * 10 + 1;
            }
            break;
            
            default:
            System.out.println("Incorrect Choice");
            break;
        }
    }
}
6. Design a class to overload a function check( ) as follows:
void check (String str , char ch ) — to find and print the frequency of a character in a string.
Example:
Input:
str = “success”
ch = ‘s’
Output:
number of s present is = 3
void check(String s1) — to display only vowels from string s1, after converting it to lower case.
Example:
Input:
s1 =”computer”
Output: o u e
public class Program6
{
    void check (String str , char ch ) {
        int count = 0;
        int len = str.length();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (ch == c) {
                count++;
            }
        }
        System.out.println("Frequency of " + ch + " = " + count);
    }
    
    void check(String s1) {
        String s2 = s1.toLowerCase();
        int len = s2.length();
        System.out.println("Vowels:");
        for (int i = 0; i < len; i++) {
            char ch = s2.charAt(i);
            if (ch == 'a' ||
                ch == 'e' ||
                ch == 'i' ||
                ch == 'o' ||
                ch == 'u')
                System.out.print(ch + " ");
        }
    }
}
7. Using the switch statement, write a menu driven program for the following:
(a) To print the Floyd’s triangle:
1
2   3
4   5   6
7   8   9   10
11 12 13 14 15
(b) To display the following pattern:
I
I C
I C S
I C S E
For an incorrect option, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program7
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for Floyd's triangle");
        System.out.println("Type 2 for an ICSE pattern");
        
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        
        switch (ch) {
            case 1:
            int a = 1;
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= i; j++) {
                    System.out.print(a++ + "\t");
                }
                System.out.println();
            }
            break;
            
            case 2:
            String s = "ICSE";
            for (int i = 0; i < s.length(); i++) {
                for (int j = 0; j <= i; j++) {
                    System.out.print(s.charAt(j) + " ");
                }
                System.out.println();
            }
            break;
            
            default:
            System.out.println("Incorrect Choice");
        }
    }
}
8. Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words, but all special words are not palindromes.
Write a program to accept a word. Check and display whether the word is a palindrome or only a special word or none of them.
import java.util.Scanner;

public class Program8
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String str = in.next();
        str = str.toUpperCase();
        int len = str.length();
        
        if (str.charAt(0) == str.charAt(len - 1)) {
            boolean isPalin = true;
            for (int i = 1; i < len / 2; i++) {
                if (str.charAt(i) != str.charAt(len - 1 - i)) {
                    isPalin = false;
                    break;
                }
            }
            
            if (isPalin) {
                System.out.println("Palindrome");
            }
            else {
                System.out.println("Special");
            }
        }
        else {
            System.out.println("Neither Special nor Palindrome");
        }
        
    }
}
9. Design a class to overload a function sumSeries() as follows:
(i) 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) void sumSeries(): to find and display the sum of the following series:
public class Program9
{
    void sumSeries(int n, double x) {
        double sum = 0;
        for (int i = 1; i <= n; i++) {
            double t = x / i;
            if (i % 2 == 0)
                sum -= t;
            else
                sum += t;
        }
        System.out.println("Sum = " + sum);
    }
    
    void sumSeries() {
        long sum = 0, term = 1;
        for (int i = 1; i <= 20; i++) {
            term *= i;
            sum += term;
        }
        System.out.println("Sum=" + sum);
    }
}
10. Write a program to input a number. Check and display whether it is a Niven number or not. (A number is said to be Niven which is divisible by the sum of its digits).
Example: Sample Input 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.
import java.util.Scanner;

public class Program10
{
    public void checkNiven() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number: ");
        int num = in.nextInt();
        int orgNum = num;
        
        int digitSum = 0;
        
        while (num != 0) {
            int digit = num % 10;
            num /= 10;
            digitSum += digit;
        }
        
        /*
         * digitSum != 0 check prevents
         * division by zero error for the
         * case when users gives the number
         * 0 as input
         */
        if (digitSum != 0 && orgNum % digitSum == 0)
            System.out.println(orgNum + " is a Niven number");
        else
            System.out.println(orgNum + " is not a Niven number");
    }
}
11. Define a class called ParkingLot with the following description:    
Data MembersPurpose
int vno To store the vehicle number
int hoursTo store the number of hours the vehicle is parked in the parking lot
double billTo store the bill amount
Member MehodPurpose
void input( ) To input the vno and hours
void calculate( )To compute the parking charge at the rate ₹3 for the first hour or the part thereof and ₹1.50 for each additional hour or part thereof.
void display()To display the detail
12. Write a main method to create an object of the class and call the above methods.
import java.util.Scanner;

public class Program11
{
    private int vno;
    private int hours;
    private double bill;
    
    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter vehicle number: ");
        vno = in.nextInt();
        System.out.print("Enter hours: ");
        hours = in.nextInt();
    }
    
    public void calculate() {
        if (hours <= 1)
            bill = 3;
        else
            bill = 3 + (hours - 1) * 1.5;
    }
    
    public void display() {
        System.out.println("Vehicle number: " + vno);
        System.out.println("Hours: " + hours);
        System.out.println("Bill: " + bill);
    }
    
    public static void main(String args[]) {
        Program11 obj = new Program11();
        obj.input();
        obj.calculate();
        obj.display();
    }
}
13. Using switch statement, write a menu driven program to:
(a) find and display all the factors of a number input by the user (including 1 and the excluding the number itself).
Example:
Sample Input : n = 15
Sample Output : 1, 3, 5
b) find and display the factorial of a number input by the user (the factorial of a non-negative integer n, denoted by n!, is the product of all integers less than or equal to n).
Example:
Sample Input : n = 5
Sample Output : 5! = 1*2*3*4*5 = 120
For an incorrect choice, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program13
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("1. Factors of number");
        System.out.println("2. Factorial of number");
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();
        int num;

        switch (choice) {
            case 1:
            System.out.print("Enter number: ");
            num = in.nextInt();
            for (int i = 1; i < num; i++) {
                if (num % i == 0) {
                    System.out.print(i + " ");
                }
            }
            System.out.println();
            break;

            case 2:
            System.out.print("Enter number: ");
            num = in.nextInt();
            int f = 1;
            for (int i = 1; i <= num; i++)
                f *= i;
            System.out.println("Factorial = " + f);
            break;
            
            default:
            System.out.println("Incorrect Choice");
            break;
        }
    }
}
14. 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 digits = 5 * 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, then display the message “Special two—digit number” otherwise, display the message “Not a special two-digit number”.
import java.util.Scanner;
public class Program14
{
    public void checkNumber() {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter a 2 digit number: ");
        int orgNum = in.nextInt();
        
        int num = orgNum;
        int count = 0, digitSum = 0, digitProduct = 1;
        
        while (num != 0) {
            int digit = num % 10;
            num /= 10;
            digitSum += digit;
            digitProduct *= digit;
            count++;
        }
        
        if (count != 2)
            System.out.println("Invalid input, please enter a 2-digit number");
        else if ((digitSum + digitProduct) == orgNum)
            System.out.println("Special 2-digit number");
        else
            System.out.println("Not a special 2-digit number");
            
    }
}
15. Design a class to overload a function area( ) as follows:
double area (double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2
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)
double area (double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)
import java.util.Scanner;

public class Program15
{
    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;
    }
    
    double area (int a, int b, int height) {
        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;
    }
}
16. 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:
Term Deposit
Recurring Deposit
For option 1, accept principal (P), rate of interest(r) and time period in years(n). Calculate and output the maturity amount(A) receivable using the formula:
A = P[1 + r / 100]n
For option 2, accept Monthly Installment (P), rate of interest (r) and time period in months (n). Calculate and output the maturity amount (A) receivable using the formula:
A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12
For an incorrect option, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program16
{
    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;
        int n = 0;
        
        switch (ch) {
            case 1:
            System.out.print("Enter Principal: ");
            p = in.nextDouble();
            System.out.print("Enter Interest Rate: ");
            r = in.nextDouble();
            System.out.print("Enter time in years: ");
            n = in.nextInt();
            a = p * Math.pow(1 + r / 100, n);
            System.out.println("Maturity amount = " + a);
            break;
            
            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");
        }
    }
}
17. 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 × digit1 + 2 × digit2 + 3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 × digit8 + 9 × digit9 + 10 × digit10 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:

Input the ISBN code as a 10-digit integer.
If the ISBN is not a 10-digit integer, output the message “Illegal ISBN” and terminate the program.
If the number is divisible by 11, output the message “Legal ISBN”. If the sum is not divisible by 11, output the message “Illegal ISBN”.
import java.util.Scanner;

public class Program17
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the ISBN: ");
        long isbn = in.nextLong();
        
        int sum = 0, count = 0, m = 10;
        while (isbn != 0) {
            int d = (int)(isbn % 10);
            count++;
            sum += d * m;
            m--;
            isbn /= 10;
        }
        
        if (count != 10) {
            System.out.println("Illegal ISBN");
        }
        else if (sum % 11 == 0) {
            System.out.println("Legal ISBN");
        }
        else {
            System.out.println("Illegal ISBN");
        }
    }
}
18. Design a class to overload a function series( ) as follows:
double series(double n) with one double argument and returns the sum of the series.
sum = (1/1) + (1/2) + (1/3) + ………. + (1/n)
double series(double a, double n) with two double arguments and returns the sum of the series.
sum = (1/a2) + (4/a5) + (7/a8) + (10/a11) + ………. to n terms
public class Program18
{
    double series(double n) {
        double sum = 0;
        for (int i = 1; i <= n; i++) {
            double term = 1.0 / i;
            sum += term;
        }
        return sum;
    }
    
    double series(double a, double n) {
        double sum = 0;
        int x = 1;
        for (int i = 1; i <= n; i++) {
            int e = x + 1;
            double term = x / Math.pow(a, e);
            sum += term;
            x += 3;
        }
        return sum;
    }
    
    public static void main(String args[]) {
        Program18 obj = new Program18();
        System.out.println("First series sum = " + obj.series(5));
        System.out.println("Second series sum = " + obj.series(3, 8));
    }
}
19. Using the switch statement, write a menu driven program:
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…
To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program19
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for Composite Number");
        System.out.println("Type 2 for Smallest Digit");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        
        switch (ch) {
            case 1:
            System.out.print("Enter Number: ");
            int n = in.nextInt();
            int c = 0;
            for (int i = 1; i <= n; i++) {
                if (n % i == 0)
                    c++;
            }
            
            if (c > 2)
                System.out.println("Composite Number");
            else
                System.out.println("Not a Composite Number");
            break;
            
            case 2:
            System.out.print("Enter Number: ");
            int num = in.nextInt();
            int s = 10;
            while (num != 0) {
                int d = num % 10;
                if (d < s)
                    s = d;
                num /= 10;
            }
            System.out.println("Smallest digit is " + s);
            break;
            
            default:
            System.out.println("Wrong choice");
        }
    }
}
20. Given below is a hypothetical table showing rates of income tax for male citizens below the age of 65 years:

Taxable income (TI) in ₹    Income Tax in ₹
Does not exceed Rs. 1,60,000    Nil
Is greater than Rs. 1,60,000 and less than or equal to Rs. 5,00,000.    (TI – 1,60,000) x 10%
Is greater than Rs. 5,00,000 and less than or equal to Rs. 8,00,000 [(TI – 5,00,000) x 20%] + 34,000
Is greater than Rs. 8,00,000    [(TI – 8,00,000) x 30%] + 94,000
Write a program to input the age, gender (male or female) and Taxable Income of a person.

If the age is more than 65 years or the gender is female, display “wrong category”. If the age is less than or equal to 65 years and the gender is male, compute and display the income tax payable as per the table given above.
import java.util.Scanner;

public class Program20
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Gender(male/female): ");
        String gender = in.nextLine();
        System.out.print("Enter Age: ");
        int age = in.nextInt();
        System.out.print("Enter Taxable Income: ");
        double ti = in.nextDouble();
        double tax = 0.0;

        if (age > 65 || gender.equalsIgnoreCase("female")) {
            System.out.print("Wrong Category");
        }
        else {
            if (ti <= 160000)
                tax = 0;
            else if (ti <= 500000)
                tax = (ti - 160000) * 10 / 100;
            else if (ti <= 800000)
                tax = 34000 + ((ti - 500000) * 20 / 100);
            else
                tax = 94000 + ((ti - 800000) * 30 / 100);
                
            System.out.println("Tax Payable: " + tax);
        }      
    }
}
21. Design a class to overload a function polygon() as follows:
void polygon(int n, char ch) — with one integer and one character type argument to draw a filled square of side n using the character stored in ch.
void polygon(int x, int y) — with two integer arguments that draws a filled rectangle of length x and breadth y, using the symbol ‘@’.
void polygon() — with no argument that draws a filled triangle shown below:
Example:
Input value of n=2, ch = ‘O’
Output:
OO
OO
Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
Output:
*
**
****
public class Program21
{
    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[]) {
        Program21 obj = new Program21();
        obj.polygon(2, 'o');
        System.out.println();
        obj.polygon(2, 5);
        System.out.println();
        obj.polygon();
    }
}
22. Using a switch statement, write a menu driven program to:
(a) generate and display the first 10 terms of the Fibonacci series
0, 1, 1, 2, 3, 5
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
(b) find the sum of the digits of an integer that is input by the user.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message should be displayed.
import java.util.Scanner;

public class Program22
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("1. Fibonacci Series");
        System.out.println("2. Sum of digits");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();

        switch (ch) {
            case 1:
            int a = 0, b = 1;
            System.out.print(a + " " + b);
            /*
             * i is starting from 3 below
             * instead of 1 because we have 
             * already printed 2 terms of
             * the series. The for loop will 
             * print the series from third
             * term onwards.
             */
            for (int i = 3; i <= 10; i++) {
                int term = a + b;
                System.out.print(" " + term);
                a = b;
                b = term;
            }
            break;

            case 2:
            System.out.print("Enter number: ");
            int num = in.nextInt();
            int sum = 0;
            while (num != 0) {
                sum += num % 10;
                num /= 10;
            }
            System.out.println("Sum of Digits " + " = " + sum);
            break;

            default:
            System.out.println("Incorrect choice");
            break;
        }
    }
}
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)
import java.util.Scanner;

public class Program23
{
    public static int fact(int y) {
        int f = 1;
        for (int i = 1; i <= y; i++) {
            f *= i;
        }
        return f;
    }

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number: ");
        int num = in.nextInt();

        int t = num;
        int sum = 0;
        while (t != 0) {
            int d = t % 10;
            sum += fact(d);
            t /= 10;
        }

        if (sum == num)
            System.out.println(num + " is a special number");
        else
            System.out.println(num + " is not a special number");

    }
}
24. Write a menu driven program to perform the following tasks by using Switch case statement:
(a) To print the series:
0, 3, 8, 15, 24, ………… to n terms. (value of ‘n’ is to be an input by the user)
(b) To find the sum of the series:
S = (1/2) + (3/4) + (5/6) + (7/8) + ……….. + (19/20)
import java.util.Scanner;

public class Program24
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 to print series");
        System.out.println("0, 3, 8, 15, 24,....to n terms");
        System.out.println();
        System.out.println("Type 2 to find sum of series");
        System.out.println("(1/2) + (3/4) + (5/6) + (7/8) +....+ (19/20)");
        System.out.println();
        System.out.print("Enter your choice: ");
        int choice = in.nextInt();

        switch (choice) {
            case 1:
                System.out.print("Enter n: ");
                int n = in.nextInt();
                for (int i = 1; i <= n; i++)
                    System.out.print(((i * i) - 1) + " ");
                System.out.println();
                break;
                
            case 2:
                double sum = 0;
                for (int i = 1; i <= 19; i = i + 2)
                    sum += i / (double)(i + 1);
                System.out.println("Sum = " + sum);
                break;
                
            default:
                System.out.println("Incorrect Choice");
                break;
        }
    }
}
25. Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket AmountDiscount
Above Rs. 7000018%
Rs. 55001 to Rs. 7000016%
Rs. 35001 to Rs. 5500012%
Rs. 25001 to Rs. 3500010%
Less than Rs. 250012%
Write a program to input the name and ticket amount for the customer and calculate the discount amount and net amount to be paid. Display the output in the following format for each customer:
Sl. No.     Name    Ticket Charges     Discount      Net Amount
(Assume that there are 15 customers, first customer is given the serial no (SI. No.) 1, next customer 2 …….. and so on)
import java.util.Scanner;

public class Program25
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String names[] = new String[15];
        int amounts[] = new int[15];

        for (int i = 0; i < 15; i++) {
            System.out.print("Enter " + "Customer " + (i+1) + " Name: ");
            names[i] = in.nextLine();
            System.out.print("Enter " + "Customer " + (i+1) + " Ticket Charges: ");
            amounts[i] = in.nextInt();
            in.nextLine();
        }

        System.out.println("Sl. No.\tName\t\tTicket Charges\tDiscount\t\tNet Amount");

        for (int i = 0; i < 15; i++) {
            int dp = 0;
            int amt = amounts[i];
            if (amt > 70000)
                dp = 18;
            else if (amt >= 55001)
                dp = 16;
            else if (amt >= 35001)
                dp = 12;
            else if (amt >= 25001)
                dp = 10;
            else
                dp = 2;

            double disc = amt * dp / 100.0;
            double net = amt - disc;

            System.out.println((i+1) + "\t" + names[i] 
                + "\t" + amounts[i] + "\t\t" 
                + disc + "\t\t" + net);
        }
    }
}

11 thoughts on “25 Important Java Programs for ICSE and ISC”

  1. I抦 impressed, I need to say. Actually hardly ever do I encounter a blog that抯 each educative and entertaining, and let me let you know, you could have hit the nail on the head. Your concept is outstanding; the problem is something that not enough people are talking intelligently about. I’m very comfortable that I stumbled across this in my seek for one thing referring to this.

  2. I would like to get across my affection for your kind-heartedness in support of persons who really need assistance with in this niche. Your very own commitment to getting the message all around had been surprisingly effective and has truly allowed individuals much like me to realize their targets. This informative facts entails a great deal to me and much more to my colleagues. Thank you; from all of us.

  3. I was just searching for this information for some time. After 6 hours of continuous Googleing, finally I got it in your site. I wonder what is the lack of Google strategy that do not rank this kind of informative websites in top of the list. Usually the top websites are full of garbage.

  4. Hi there, just became aware of your blog through Google, and found that it is truly informative. I am going to watch out for brussels. I will appreciate if you continue this in future. Numerous people will be benefited from your writing. Cheers!

  5. Good web site! I truly love how it is easy on my eyes and the data are well written. I am wondering how I could be notified whenever a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a nice day!

Leave a Reply

Your email address will not be published. Required fields are marked *