Skip to main content

REQUESTED PROGRAM 1

PROGRAM:   REQUESTED  BY ANKUR ACHARYA.

ISC 2016 QUESTION

Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. The words are separated with a blank space, and are in uppercase.

Perform the following:

Find the number of words beginning and ending with a vowel.
Place the words which begin and end with a vowel at the beginning, followed by the remaining words as they occur in the sentence.

Test your program with the sample data and some random data:

Example 1:
INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL.

Example 2:
INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY.

Example 3:
INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 0
LOOK BEFORE YOU LEAP.

Example 4:
INPUT: HOW ARE YOU@
OUTPUT: Sentence must begin with ‘.’, ‘!’ or ‘?’.


SYNTAX


import java.io.*;
import java.util.*;
class Vowels_seperable
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String s,nstr="";int c=0;
        System.out.println("ENTER A STRING");
        s=br.readLine();
        Boolean flag1=false,flag2=false;
        s=s.trim();
        String vowel="",conso="";
        int l=s.length();
        s=s.toUpperCase();
        String s1= s.substring(0,l-1);
        if((s.charAt(l-1)=='.')||(s.charAt(l-1)=='?')||(s.charAt(l-1)=='!'))
        {
            String []a=s1.split(" ");
            for(int z=0; z<a.length;z++) {
                nstr=a[z];
                char ch=nstr.charAt(0);
                switch (ch){
                    case 'A': 
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':flag1=true;
                    break;
                    default : flag1=false;
                }
                char ch1= nstr.charAt(nstr.length()-1);
                switch (ch1){
                    case 'A': 
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':flag2=true;
                    break;
                    default : flag2=false;
                }
                if(flag1==true &&flag2==true){
                    vowel+=nstr+" ";c++;}
                else
                    conso+=nstr+" ";
            }
            String fin=vowel+conso;
            fin.trim();
            System.out.println("NUMBER OF WORDS STARTING AND ENDING WITH VOWELS: "+c);
            System.out.println(fin);
        }
        else System.out.println("SENTENCE MUST END WITH . ? or !");
    }}

TESTED OK.

Comments

Popular posts from this blog

LUCKY NUMBER

PROGRAM : LUCKY NUMBER QUESTION: Consider the sequence of natural numbers. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 …………………………………. Removing every second number produces the sequences 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 …………………………. Removing every third number produces the sequences 1, 3, 7, 9, 13, 15, 19, 21, 25 …………………………. This process continues indefinitely by removing the fourth, fifth…and so on, till after a fixed number of steps, certain natural numbers remain indefinitely. These are known as  Lucky Numbers . Write a program to generate and print lucky numbers less than a given number N. SAMPLE INPUT :   N = 10 OUTPUT :   The Lucky numbers less than 10 are:     1     3     7 SAMPLE INPUT :   N = 25 OUTPUT :   The Lucky numbers less than 25 are:     1     3  ...

SMITH NUMBER

PROGRAM: SMITH NUMBER A   Smith number  is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 58, 85, 94, 121 ……………….. For Example 58=> 5+8=13 2+(2+9) of 29 =13 Since sum of digits=sum of digits of prime factors 58 is a SMITH NUMBER SYNTAX: import java.io.*; class smith_no { static int sum,sum1;     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int c=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         int n1=n;         while(n1!=0){         int d=n1%10;         sum1+=d; ...

Disarium Number

AJ Java Programs Program 4: Disarium Number A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example  135 is a DISARIUM (Workings 1 1 +3 2 +5 3  = 135, some other  DISARIUM  are 89, 175, 518 etc) Syntax: import java.io.*; class disarium {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,n1,n2,c=0,sum=0,d=0;         System.out.println("Enter a Num");         n=Integer.parseInt(br.readLine());         n2=n1=n;         while(n2!=0)         {             n2=n2/10;             c++;         }       ...