0% found this document useful (0 votes)
42 views2 pages

Java Program: Vowel Count & Uppercase Conversion

This Java program counts the number of vowels (a, e, i, o, u) in a text file. It takes the text file as input, iterates through each character, checks if it is a vowel and increments the count. It then prints each vowel and its occurrence count. A second Java program reads a text file, converts each character to uppercase and writes it to a new output file.

Uploaded by

avishana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Java Program: Vowel Count & Uppercase Conversion

This Java program counts the number of vowels (a, e, i, o, u) in a text file. It takes the text file as input, iterates through each character, checks if it is a vowel and increments the count. It then prints each vowel and its occurrence count. A second Java program reads a text file, converts each character to uppercase and writes it to a new output file.

Uploaded by

avishana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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