Pages

Wednesday, January 4, 2023

ICSE Java Programming Character Array 2022 Q3 Specimen Paper Solved

  ICSE Java Programming Character Array  2022 Q3 Solved


PYTHON CODE

char_array = []
array_size = 10
upper_counter = 0
vowel_counter = 0
vowel =['A', 'E', 'I', 'O', 'U' ]
print("Enter the characters in the array:")
for i in range(array_size):
    print("Enter the element at the position:",(i+1))
    char_array.append(str(input()))
for i in range(array_size):
    if char_array[i] >= 'A' and char_array[i] <= 'Z':
        print(char_array[i]," is an upper case character.")
        upper_counter +=1
for i in range(array_size):
    for j in range(5):
        if char_array[i] == vowel[j] or str(char_array[i]).upper() == vowel[j]:
            print(char_array[i]," is an vowel.")
            vowel_counter +=1
print("Total number of uppercase characters =",upper_counter)
print("Total number of vowels =",vowel_counter)


JAVA CODE

import java.util.Scanner;

public class ICSEJava2022 {
    public static void main(String[] args) {
        characterArray obj = new characterArray();
        obj.input();
        obj.display();
    }
}

class characterArray {
    public void display() {
        for (int i = 0; i < this.array_size; i++) {
            if (this.char_array[i] >= 65 && this.char_array[i] <= 90) {
                System.out.println(this.char_array[i] + " is an upper case character.");
                this.upper_counter++;
            }
            for (int j = 0; j < 5; j++)
                if (this.char_array[i] == this.vowel[j] || (char) (this.char_array[i] - 32) == this.vowel[j]) {
                    System.out.println(this.char_array[i] + " is an vowel.");
                    this.vowel_counter++;
                }
        }
        System.out.println("Total number of upper case characters =" + this.upper_counter);
        System.out.println("Total number of vowels =" + this.vowel_counter);
    }

    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the characters in the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element at the position " + (i + 1));
            this.char_array[i] = in.next().charAt(0);
        }
        in.close();
    }

    characterArray() {
        this.array_size = 10;
        this.char_array = new char[this.array_size];
        this.upper_counter = 0;
        this.vowel_counter = 0;
    }

    private char[] char_array;
    private static char[] vowel = { 'A', 'E', 'I', 'O', 'U' };
    private static int array_size;
    private int upper_counter;
    private int vowel_counter;

}

No comments:

Post a Comment