Program – no. of words starts with Vowel


Write a Java program to input a sentence and count the number of words that start with a vowel (A, E, I, O, U). The program should be case-insensitive and display the count.

Example:
Input: "An elephant is outside the umbrella"
Output: Number of words starting with a vowel: 4

import java.util.Scanner;

public class VowelWordCounter {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Input sentence
        System.out.print("Enter a sentence: ");
        String sentence = sc.nextLine();
        sc.close();

        int vowelWordCount = 0;
        int length = sentence.length();
        boolean isWord = false; // Flag to track a new word

        for (int i = 0; i < length; i++) {
            char ch = sentence.charAt(i);

            // Check if current character is a letter (indicating start of a word)
            if (Character.isLetter(ch)) {
                if (!isWord) { // New word detected
                    isWord = true;
                    char firstChar = Character.toLowerCase(ch); // Convert to lowercase
                    if ("aeiou".indexOf(firstChar) != -1) { // Check if it starts with a vowel
                        vowelWordCount++;
                    }
                }
            } else {
                isWord = false; // Reset flag when encountering space or punctuation
            }
        }

        // Output the count
        System.out.println("Number of words starting with a vowel: " + vowelWordCount);
    }
}

Loops through each character in the sentence.
Detects the start of a word (first letter after a space or punctuation).
Checks if the first letter is a vowel (aeiou).
Counts only words that start with vowels.

Output:

Enter a sentence: An elephant is outside the umbrella
Number of words starting with a vowel: 4

6th Year -Happy Anniversary


Thank you Universe…

Thank you WordPress…

Thank you Subscribers …

Thank you Visitors…

I am really thankful to everyone visited my blog and please comment your valuable feedback. WordPress, has given me a platform to share my programming topics to entire world. Surprisingly this is the 6th year. Realizing that I am not consistent in doing blog. Before a couple of days I could retrieve my logins after 1-2 years. In this 6th year anniversary, I like to resume my blogging of ISC, ICSE Computer topics.

final keyword – variable into constant- 2 marks


Rating: 5 out of 5.

final keyword – converts the variable into constant whose value cannot be changed at any stage in the program.

Syntax:
final datatype variable name=actual value

eg: final int a=15; // value of ‘a’ is constant as 15

Find the output:

int x=10;
final int y=20;
x=x+4;
y=y+4;

What is the updated value of x and y? or Displays any error message, then What is the reason?

Compile time error message – cannot assign a value to final variable ‘y’

Explanation:

int x=10; // an integer variable.

final int y= 20; // an integer variable declared as constant, so value of ‘y’ //cannot be changed anywhere in the program

x=x+4; //change the value of ‘x’ by adding 4 to it.

// so the value of ‘x’ is 14 (10+4)

y=y+4; //value of y’ will not be changed as keyword final has converted //variable ‘yinto constant

// In this case during compilation of the program the error message “Cannot assign a value to final variable y”

ICSE-Computer Applications- October 2018


                                  Section A (40 Marks)
                                Answer all questions.

Question 1                                                                                                                              [10]

  1. Declare a single dimensional array of 10 integer values.
  2. Convert the following while loop to the corresponding for loop.
    int m=5, n=10;

while(n>=1)   {
System.out.println(m*n);
n–;
}

  1. Convert the following segment into an equivalent do loop:

int x,c;

for(x=10, c=20;c>=20;c=c-2)

x++:

  1. What is the final value of ctr when the iteration process given below, executes?

int ctr=0;
for(int j=1;j<=5;j+=2)
++ctr;

  1. If, array[]={1,4,5,6,3,32,23,90}; i) What is array.length?  ii) What is array[10]?

Question 2                                                                                                                                [10]

  1. Which keyword used to acquire the properties of one class to another class?
  2. Here is a skeleton definition of a class
    class Sample {
    int i;
    char c;
    float f;
    } Implement the constructor.
  3. Write a program to check whether the given number is palindrome or not.
  4. Differentiate between public and private modifiers for members of a class.
  5. What type of inheritance does Java here?

Question 3                                                                                                                                [10]

  1. Write a program to print Fibonacci series i.e., 0 1 1 2 3 5 8…..The number of terms required, is to be passed as parameter.
  2. What will be the result stored in x after evaluating the following expression?
    int x =42;
    x+ = (x++ ) + (++x) +x;
  3. What will be the output of the following code?

int m=3;

int n=15;

for(int i=1;i<5;i++)

m++;

–n;

System.out.println(“m=”+m);

System.out.println(“n=”+n);

  1. Analyze the following program segment and determine how many times the loop will be executed and what will be the output of the program segment?
    int p=200;

while(true)

{

if(p<100)

break;

p=p-40;

}

System.out.println(p);

  1. The following is a segment of a program

x=1; y=1;
if(n>0)  {

x=x+1;
y=y+1;}

What will be the value of x and y, if n assumes a value  i)1  ii) 0 ?

Question 4                                                                                                                                [10]

  1. Give two differences between the switch statement and if else statement.
  2. Write two difference between linear search and binary search.
  3. Given that in x[][]={{2,4,6},{3,5,7}}, what will be the value of x[1][1] and x[0][2]?
  4. State the total size in bytes, of the arrays a[4] of char data type and p[6] of float data type.
  5. If int x[]={4,3,7,8,9,10}; What are the values of p and q?
    i) p= x.length     ii)   q=x[2] +x[5] * x[1]

   

 

         Section B (60 Marks)
Attempt any four questions from this Section.

      The answers in this Section should consist of the Programs in either BlueJ

environment or any program environment with Java as the base.

Each program should be written using Variable descriptions/Mnemonic Codes
such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 5                                                                                                                              [15]
Designa 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.

  1. 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.

Example:

  1. i) Input value of n=2, ch=’O’

Output: OO
OO

  1. ii) Input value of x=2,y=5

Output

@@@@@

@@@@@

 

iii) Output

*

* *

* * *

 
Question 6                                                                                                                              [15]

Write  a menu driven program  to accept a number and check and display whether it is a prime number or not OR an automorphic number or not.

  1. a) Prime number : A number is said to be a prime number if it is divisible only by 1 and itself and not by any other number. Example; 3,5,7,11,13..
  2. b) Automorphic number : An automorphic is the number which is contained in the last digit of the square. Example : 25 is an automorphic number as its square is 625 and 25 is present as the last two digits.

 

Question 7                                                                                                                              [15]

Special words are those words which start and end with the same letter.
Examples:  EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.

Examples: MALAYALAM, MADAM, LEVEL, ROTATOR

All palindromes are special words, but all special words are not palindromes.

Write a program to accept a word check and print whether the word is a palindrome or only special word.

Question 8                                                                                                                              [15]
Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word, convert the word into upper case and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end following by  “YZ”.

Sample input : Flowers     Sample Output: OWERSFLYZ
Sample input : Olympics            Sample Output : OLYMPICSYZ

Question 9                                                                                                                             

 1)  Write a program to initialize the given data in an array and find the minimum and maximum    values along with the sum of the given elements.                                                                                                                             [5]

Numbers: 2 5 4 1 3

Output: Minimum value  : 1
Maximum value=5

Sum of the elements=15

 

2) Write a program to accept 15 integers from the keyboard, assuming that no integer entered is a zero. Perform selection sort on the integers and then print them in ascending order.        [10]

 

Question 10                                                                                                                            [15] Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order using the bubble sort technique only.

Input:  Calcutta, Agra, Mumbai, Bangalore, Delhi

Output: Agra, Bangalore, Calcutta, Delhi, Mumbai

 

.

ICSE


  1. Define abstraction.
  2. Define escape sequence with examples.
  3. Write a difference between the functions isUpperCase( ) and toUpperCase( ).
  4. How are private members of a class different from public members?
  5. Classify the following as primitive or non-primitive datatypes:
    (i) char(ii) arrays(iii) int(iv) classes

Model Question ICSE Computer Applications 2018


Question 1                                                                                                                              [10]

  1. What is dynamic initialization, with an example?
  2. How are the following passed in Java? i) primitive types ii) reference types
  3. Consider the following class:
    public class myClass {
    public static int x=3, y=5;
    public int a=2, b=3; }
    i)          Name the variables for which each object of the class will have its own
    distinct copy.
  4. ii) Name the variables that are common to all objects of the class.
  5. Create a class with one integer instance variable and one class variable. Initialize the variable using i) default constructor (ii) parameterized constructor
  6. Write a java statement to create an object mp4 of class digital.

Question 2                                                                                                                               [10]

  1. Differentiate between String and Stringbuffer type data.
  2. Here is a skeleton definition of a class
    class Sample {
    int i;
    char c;
    float f;
    } Implement the constructor.
  3. What will be the output of the following code fragment?
    If the input given is i) 7 ii) 5
    if(a=5)
    out.println(“Five”);
    else
    System.out.println(“Not Five”);
  4. Differentiate between
    i) equals() and compareTo() with examples and return value.
  5. ii) throw and throws
  6. Write an expression in Java for  x4+ 6x2 + 25 / x

Question 3                                                                                                                               [10]

  1. What are the values of x and y when the following statements are executed?
    int a=63, b=36;
    boolean x=(a>b) ?a:b;
    int y=(a<b)?a:b;
  2. What will be the result stored in x after evaluating the following expression?
    int x =4;
    x+ = (x++ ) + (++x) +x;
  3. State the method that:
    i) Converts a string to a primitive float data type.
  4. ii) Determines if the specified character is an uppercase characters.
  5. Write the Identifier Naming Rules. (All rules)
  6. Rewrite the following program segment using the if –else statements instead of the ternary operator.

String grade= (mark >= 90)?”A”: (mark >=80)? “B”: “C”;

Question 4                                                                                                                               [10]

  1. Give the output of the following code
    double m=6.25, n=7.45;
    out.println(Math.sqrt(m));

System.out.println(Math.min(m,n));

System.out.println(Math.abs(6.25-7.45));
System.out.println(Math.ceil(m));

  1. Name the type of error (syntax, runtime or logical error) in each case given below:
    i) Division of a variable that contains a value of zero.
    ii) Multiplication operator used when the operation should be division
    iii) Missing semicolon
  2. Write a java statement to input/read the following from the user using the keyboard.
  3. Character ii) String (using scanner class)
  4. Write about the differences between Primitive and Reference data types with example.
  5. What is temporary instance with example?

     Section B (60 Marks)
Attempt any four questions from this Section.

      The answers in this Section should consist of the Programs in either BlueJ

environment or any program environment with Java as the base.

Each program should be written using Variable descriptions/Mnemonic Codes
such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 5                                                                                                                              [15]
Given below is a  hypothetical table showing rate of income tax for male citizens below the age of 65 years.
Taxable income(Ti) in Rs.                                                    Income Tax in Rs.
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)* 10%
Is greater than Rs. 5,00,000 and less than or
equal to Rs. 8,00,000                                                      [(Ti – 5,00,000) * 20%] +34,000
Is greater than Rs. 8,00,000                                                    [(Ti – 8,00,000)* 30%] + 94,000

 

Write a program to input that 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.
Question 6                                                                                                                              [15]

 

Define a class Library having the following description:

Instance variables/Data members:

int acnum        stores the accession number of the book

String title       stores the title of the book

String author   stores name of the author.

Member Methods:

  1. void input() –           to input and store accession number, title and author.
  2. void compute() –           to accept the number of days late, calculate and display the fine charge at the rate Rs. 2 per day.
  • void display() –           to display the details in the following format:

 

Accession number                             Title                            Author

Write a main() to create an object of the class and call the above member methods.

 

Question 7                                                                                                                              [15]

Write a program to accept a word and convert it into lower case if its in uppercase and display the new word by replacing only the vowels with the preceeding characters.

Sample Input : computer
Sample Output : cnmpttdr

 

Question 8                                                                                                                              [15]

Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word, convert the word into upper case and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end following by  “YZ”.

Sample input : Flowers     Sample Output: OWERSFLYZ
Sample input : Olympics         Sample Output : OLYMPICSYZ
Question 9                                                                                                                              [15]

 

Design a class named FruitJuice with the following description:

Instance variables/Data members:

int product_code         –           stores the product code number

String flavor                –           stores the flavor of the juice (eg: orange, apple etc.)

String pack_Type        –           stores the type oif packaging (eg:tetra-pack, PET bottle etc.)

int pack_size               –           stores package size(eg: 200mL, 400 mL, etc.)

int product_price         –           stores the price of the product.

Member Methods:

  1. FruitJuice() –           deault constructor to initialize integer data members to 0 and String data members to “”
  2. void input() –           to input and store the product code, flavor, pack type, pack size and product price.
  • void discount() –           to reduce the product price by 10%.
  1. void display() –           to display the product code, flavor, pack type, pack size and product price.

Write a main method to create an object of the class and call the above member methods.

 

Question 10                                                                                                                            [15]

Design a class to overload a function JoyString() as follows:

  1. void JoyString(String s, char c1, char c2) :  with one string argument and two character arguments that replaces the character argument c1 with the character argument c2 in the given string s and prints the new string with first character as uppercase.

Example:  s=”technology”
c1=’a’, c2=’o’
Output: “Technology”

  1. void JoyString(String s1, String s2) : check and print string having more characters compared to the other one.
  • void JoyString(String s) : prints the position of the first space and last space of the given string s.
    Example :  Input value of= “Cloud computing means Internet based computing”
    Output: First index= 5, Last index = 36

Write the main() and call the above member methods.

 

Random numbers


class TEST
{
public static void main(String a[]){
System.out.println(“Random number between 0 and 1 : ” + Math.random());
System.out.println(“Random number between 0 and 1 : ” + Math.random());

// Now let’s get random number between 1 and 10
for(int i=1;i<=6;i++)
{
System.out.println(“Random value between 0 and 6 : ”
+ getRandomInteger(0,6));
}

public static int getRandomInteger(int maximum, int minimum){
return ((int) (Math.random()*(maximum – minimum))) + minimum;
}

Output:

Random value between 0 and 6 : 1
Random value between 0 and 6 : 5
Random value between 0 and 6 : 6
Random value between 0 and 6 : 2
Random value between 0 and 6 : 6
Random value between 0 and 6 : 6

 

Welldone my dear students


Really, I am so glad to share my students results that declared on today at 3 pm from the council. ICSE and ISC results and my students of 66 from ICSE and 3 students from ISC has secured 100% success in all subjects. Especially for computer science one centum in ICSE and with 30 out of 66 scored above 95. ISC students secured 89 as highest marks and one of my computer science student is the school first. Today again I am proud to be as a teacher for my students. God gave me another golden quill to me as the way of my students result. 

To find the sum of the given digits


Write a program in Java to find the sum of the given digits.

import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException
{
int n,sum=0,rem;
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println(“Enter the value of ‘n’ : “);
n=Integer.parseInt(br.readLine());
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
System.out.println(“The sum of digits : “+sum);
}
}

 

Output:

Enter the value of ‘n’ :
12345
The sum of digits : 15

To find the sum of the first ‘n’ natural numbers – while loop


Write a program in java to find the sum of  the first ‘n’ natural numbers.

import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException
{
int n,sum=0,i=1;
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println(“Enter the value of ‘n’ : “);
n=Integer.parseInt(br.readLine());
while(i<=n)
{
sum=sum+i;
i++;
}
System.out.println(“The sum of  first”+n+ “natural numbers:”+sum);
}
}

Output:

Enter the value of ‘n’ :
15
The sum of  first 15 natural numbers: 120

Write a program to input a word from the user and remove the duplicate characters present in it.


Write a program to input a word from the user and remove the duplicate characters present in it.

Example:

INPUT – abcabcabc
OUTPUT – abc

INPUT – javaforschool
OUTPUT – javforschl

INPUT – Mississippi
OUTPUT – Misp

Programs:

import java.io.*;

class RemoveDupChar

{

public static void main(String args[])throws IOException

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(“Enter any word : “);

String s = br.readLine();

int l = s.length();

char ch;

String ans=””;

for(int i=0; i<l; i++)

{

ch = s.charAt(i);

if(ch!=’ ‘)

ans = ans + ch;

s = s.replace(ch,’ ‘); //Replacing all occurrence of the current character by a space

}

System.out.println(“Word after removing duplicate characters : ” + ans);

}

}

Output:

Example 1:
Enter any word : Mississippi
Word after removing duplicate characters : Misp

Example 2:
Enter any word : Attitude
Word after removing duplicate characters : Atiude

FREQUENCY OF CHARACTER IN A STRING – using array


Java program to find the frequency of each character in a given string:

import java.util.Scanner;
public class freqSample
{
public static void main(String args[])
{
String str;
int i, length, count[] = new int[256];
Scanner scanner = new Scanner(System.in);
System.out.println(“Enter a String”);
str = scanner.nextLine();
length = str.length();
// Count the frequency of each character and store
// it in count array (count[])
for (i = 0; i < length; i++)
{
count[(int) str.charAt(i)]++;
}
// Print Frequency( number of times each character occured in a string)

for (i = 0; i < 256; i++) {
if (count[i] != 0) {
System.out.println((char) i + ” – ” + count[i]);
}
}
}
}

 

Output:

Enter a String
school
c – 1
h – 1
l – 1
o – 2
s – 1

Design a class to overload a function compare()


Design a class Perform to overload a function  as follows:
(i) void compare (int, int)    – to compare two integer values and print the greater of the two integers.
(ii) void compare(char, char)  – to compare the numeric value of two characters and print with the higher numeric value.
(iii)void compare(String, String)  –  to compare the length of the two strings and print the longer of the two.

Answer:

class Perform
{
void compare(int m, int n)
{
if(m > n)
System.out.println(“The first number is greater”+m);
else
System.out.println(“The second  number is greater”+n);
}
void compare(char c, char d)
{
if(c > d)
System.out.println(“The first character is greater and the numeric  value”+(int)c);
else
System.out.println(“The second character is greater and the numeric  value”+(int)d);
}
void compare(String s1, String s2)
{
if(s1.compareTo(s2) > 0)
System.out.println(“The first string is longer”+s1);
else
System.out.println(“The second string is longer”+s2);
}

}

Analyze the given code fragment


Analyze the given program segment and answer the following questions :
(i) Write the output of the code snippet.
(ii) How many times does the body of the loop gets executed?

for(int a=5; a<=20; a+=5)
{
if(a%3 == 0)
break;
else
if(a%5 == 0)
System.out.println(a);
continue;
}

answer :
(i) 5 10
(ii) 3 times

Working :

When a = 5,
if(a%3 == 0) is false
if(a%5 == 0) is true
so it prints ‘5’
Loop executed 1 time.

When a = 10,
if(a%3 == 0) is false
if(a%5 == 0) is true
so it prints ‘10’
Loop executed 2 times.

When a = 15,
if(a%3 == 0) is true
so, break is encountered and loop terminates.
Loop executed 3 times.

 

ISC Computer Science Practical – Marking pattern


ISC Computer science —  practical paper(30 marks)

Marking procedure for practical paper

Total Marks : 30

Algorithm : 3 marks

Program : 5 marks

Comments/Mnemonics code : 2 marks

Printed code that compiled correctly : 2 marks

Run the code and get correct output : 5 marks

Viva – 3 marks

Programs done in lab class throughout the year : 10 marks ( 5 from external examiner and 5 mark from your computer teacher)