ISC 2015, Computer Practical Prog. 3

//Solution to ISC Practical Prog.3 (with formatted output)
//using printf() method, see below…

import java.io.*;
public class ISC_2015_3
{
public static void main() throws IOException
{
InputStreamReader x = new InputStreamReader(System.in);
BufferedReader y = new BufferedReader(x);
int i,j,v=0,con=0;
System.out.println(“Enter a sentence ending with a . or ?”);
String s=y.readLine();
String nstr=””,w=””;
s=s.toLowerCase();
int l=s.length();
char chr,ch=s.charAt(l-1);
if((ch==’.’)||(ch==’?’))
{
s=s.substring(0,l-1);
s=s+” “;
l=s.length();
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(ch!=’ ‘)
w=w+ch;

else
{
chr=Character.toUpperCase(w.charAt(0));
w=chr+w.substring(1);
nstr=nstr+w+” “;
w=””;
}
}
System.out.println(nstr);
System.out.printf(“%s %15s %15s\n”,”Word”,”Vowels”,”Consonants”);
s=nstr;
l=s.length();
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(ch!=’ ‘)
w=w+ch;

else
{
int wl=w.length();
System.out.printf(“%-15s”,w);
w=w.toUpperCase();
for(j=0;j<wl;j++)
{
chr=w.charAt(j);
if(chr==’A’||chr==’E’||chr==’I’||chr==’O’||chr==’U’)
v++;
else
con++;
}
System.out.printf(“%d%15d \n”,v,con);
w=””;
}
}
}
else
System.out.println(“INVALID INPUTS”);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s