You are on page 1of 2

import java.io.

*;
import java.util.Scanner;

public class WordCount {

public static void main(String[] args) throws FileNotFoundException {

//chCount
int acount=0;
File f=new File("C:\\Users\\ishu\\Desktop\\Demo.txt.txt");
Scanner input = new Scanner(f);
String sen=input.nextLine();
System.out.println(sen);

char s[]={'a','e','i','o','u'};
char l[]={'A','E','I','O','U'};

for(int vowels=0;vowels<5;vowels++)
{

for(int i=0;i<sen.length();i++)
{
char ch=sen.charAt(i);
if(ch==s[vowels] || ch==l[vowels])
{
++acount;
}
}
if(acount!=0)
System.out.println(s[vowels]+" occurs "+acount+"
times");
acount=0;
}
}

File program to read and convert to upper case:

import java.io.*;
import java.util.Scanner;

public class WordCount {

public static void main(String[] args) throws Exception {

int ch;
FileReader f=new FileReader("D://java team/Third
yr/notes/FileSample.txt");
FileWriter fw=new FileWriter("D://java team/Third
yr/notes/FileSample1.txt");
while((ch=f.read())!=-1)
{
//System.out.print((char)ch);
Character c1=new Character((char)ch);
char cc=c1.toUpperCase((char)ch);
System.out.print(cc);
fw.write(cc);
}
fw.close();
}
}

You might also like