Navbar

Tuesday, 27 April 2021

ISC COMPUTER PRACTICAL - 2021 - QUESTION 2 (String Program)

 

ISC 2021 Computer Practical Question 2 –  String Program.


-WRITTEN BY CODERGURUJI


      

     

   Solution :



import java.util.*;
class Q2
{
public static void main(String args[])
{  String x="";
int h=0,z=0;
Scanner sc= new Scanner(System.in);
System.out.println("Enter para");
String n=sc.nextLine();
String a[]=new String[1000];
int l=n.length();
for(int i=0;i<l;i++)
{
char ch=n.charAt(i);
if(ch=='.'||ch=='?'||ch=='!')
{
z++;
}
}
if(z==2)
{
for(int i=0;i<l;i++)
{
char ch=n.charAt(i);
if(ch=='.'||ch=='?'||ch=='!')
{
String p=(n.substring(0,i+1));
String m=(n.substring(i+2,l));
n=p+m;
System.out.println(n.substring(0,i+1));
System.out.println(n.substring(i+1));
break;
}
}
for(int i=0;i<l-1;i++)
{
char ch=n.charAt(i);
if(ch!='.'&&ch!='?'&&ch!='!'&&ch!=' ')
{
x=x+ch;
}
else
{
a[h]=x;
h++;
x="";
}
}
System.out.println("COMMON WORDS  FREQUENCY");
for(int i=0;i<h;i++)
{
int c=1;
for(int j=i+1;j<h;j++)
{
if(a[i].equals(a[j]))
{
for(int k=j;k<h-1;k++)
a[k]=a[k+1];
h--;
c++;
}
}
if(c>1)
System.out.println(a[i]+"\t\t"+c);
}
}
else
{
System.out.print("INVALID INPUT");
}
}
}

----------------------------end--------------------------------------------------



2 comments:

  1. The second example doesn't work with this code.

    ReplyDelete
  2. This is a really insightful blog on making Computer Science easier and more engaging for learners. I especially liked the focus on building strong concepts instead of just memorising topics. Finding the right tuition of Computer Science can make learning much smoother, and platforms like Ziyyara can offer helpful guidance through experienced tutors.

    Contact us at 9654271931.
    Visit: tuition classes of Computer Science.

    ReplyDelete