Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: April 2023

Sunday, April 30, 2023

ICSE Java Programming Function Overload 2017 Q8 Solved

ICSE Java Programming Design a class to overload a function 2017 Q8 Solved 



import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s;
        char c;
        System.out.println("Enter the string");
        s = in.nextLine();
        System.out.println("Enter the character");
        c = in.nextLine().charAt(0);
        StringCheck obj = new StringCheck();
        obj.check(s, c);
        obj.check(s);
        in.close();
    }
}

class StringCheck {
    public void check(String str, char ch) {
        for (int i = 0; i < str.length(); i++) {
            if (ch == str.charAt(i))
                counter++;
        }
        System.out.println("Number of times " + ch + " present is " + counter);
    }

    public void check(String str) {
        str = str.toLowerCase();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
                    || str.charAt(i) == 'u')
                System.out.print(str.charAt(i) + " ");
        }
    }

    StringCheck() {
        counter = 0;
    }

    private int counter;
}

ICSE Java Programming Switch Case 2017 Q7 Solved

 

ICSE Java Programming  2017 Q7 Solved

Finding the sum, largest and the smallest element of an array with 20 integer elements.




import java.util.Scanner;

public class ICSEJava {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] array = new int[20];
        int sum = 0;
        int max = 0;
        int min = 0;
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < 20; i++) {
            System.out.println("Enter the element at the position:" + (i + 1));
            array[i] = in.nextInt();
            sum += array[i];
        }
        max = array[0];
        min = array[0];
        for (int i = 0; i < 20; i++) {
            if (max < array[i])
                max = array[i];
            if (min > array[i])
                min = array[i];
        }
        System.out.println("Sum of the elements of the array is "+sum);
        System.out.println("Largest number  of the array is "+max);
        System.out.println("Smallest number of the array is "+min);
        in.close();
    }
}