ISC 2014 Computer Science Practical Paper (Solved !)

ISC 2014 Computer Practical Question.

Q3. Write a program to accept a sentence which may be terminated by either '.', '!' or '?' only. Any other character may be ignored. The words may be seperated by more than one blank space and are in upper case.
Perform the following task
  1.  Accept a sentence and reduce all the extra blank space between two words to a single blank space.
  2. Accept a word from the user which is a part of the sentence along with its position number and the deleted word and display the sentence. 

OUTPUT:

/**
 * This question came in ISC COMPUTER PRACTIALS 2014
 * THE PROGRAM HAS BEEN EXPLAINED WITH THE HELP OF LUCID COMMENTS
 */
import java.io.*;
class isc2014_q3
{
static String str=new String();//To accept and store the string
static String search_word=new String();//To accept and store the word which is to be deleted/
static int n=0;//To store the osition of the deleted word
String remove_extra_blankspace(String x)throws IOException//This function removes any extra blank spaces
{
    x=x+" ";
    String temp="";
    for(int i=0;i<x.length()-1;i++)
    {
    if(x.charAt(i)==' ' && (x.charAt(i+1)==' ' ))
        continue;
        else
        temp+=x.charAt(i);
    }
    return temp;
}
boolean validate_string(String x)throws IOException//This function validates the string
    {
        for(int i=0;i<x.length();i++)
        if(x.charAt(i)=='.'||x.charAt(i)=='!'||x.charAt(i)=='?')
        return true;
        return false;
    }
String replace()throws IOException
{
str=str.substring(0,str.length()-1);//TO REMOVE THE FULL STOP
str=str+"  ";
String store="";
int c=0;
int b=0;
for(int i=0;i<str.length();i++)
    {
        if(str.charAt(i)==' ')
        {
            String temp=str.substring(b,i);
            b=i+1;
            c++;
            if(c==n && temp.equals(search_word))
            continue;
            else
            store=store+(temp+" ");
        }
    }
    store=store+".";    
    return store;
}
public static void main()throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(read);
String fixed_string="";
isc2014_q3 ob =new isc2014_q3();
System.out.print("INPUT :");
str=br.readLine();
if(ob.validate_string(str)==false)
System.out.println("INVALID STRING");
else
{
System.out.print("WORD TO BE DELETED :");
search_word=br.readLine();
System.out.print("WORD POSITION IN THE SENTENCE :");
n=Integer.parseInt(br.readLine());
fixed_string=ob.remove_extra_blankspace(str);
str=fixed_string;
System.out.println("OUTPUT :"+ob.replace());
}
}
}

2 comments:

  1. If there are multiple spaces between words then this program is invalid.

    ReplyDelete
  2. Water Hack Burns 2 lb of Fat OVERNIGHT

    Well over 160 thousand women and men are trying a easy and secret "liquids hack" to drop 2 lbs each night in their sleep.

    It is effective and it works on everybody.

    This is how to do it yourself:

    1) Go grab a drinking glass and fill it with water half full

    2) And now do this awesome HACK

    so you'll be 2 lbs lighter as soon as tomorrow!

    ReplyDelete