InfoClusters
Information at sight.

JAVA QUESTION – Write a java program to open a text file called input.txt, reads from it a line of text, and prints it on the console having all vowels in upper case.

85
Reading time: < 1 min

Question: 

Write a java program to open a text file called input.txt, reads from it a line of text, and prints it on the console having all vowels in upper case.

Solution:

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

public class Vowels{
    public static void main(String[] args) throws Exception{
        int choice;
        Scanner sc2=new Scanner(System.in).useDelimiter("\n");;
        boolean torun=true;
        while(torun){
        System.out.println("\n\n");
        System.out.println("Press:\n1. Check Vowels.\n2. Exit.");
        System.out.println("Enter choice: ");
        choice=sc2.nextInt();
        switch(choice){
        case 1:{
        FileOutputStream fout=new FileOutputStream("input.txt");
        System.out.println("Enter the String: ");
        String s=sc2.next();
        byte b[]=s.getBytes();
        fout.write(b);
        fout.close();

        FileInputStream fin=new FileInputStream("input.txt");
        Scanner sc=new Scanner(fin);
        System.out.println("Vowels in the given String is: ");
        while(sc.hasNext()){
            String c=sc.nextLine();
            for(int i=0;i<c.length();i++){
                if(c.charAt(i)=='a'||c.charAt(i)=='A'||c.charAt(i)=='e'||c.charAt(i)=='E'||c.charAt(i)=='I'||c.charAt(i)=='i'||c.charAt(i)=='o'||c.charAt(i)=='O'||c.charAt(i)=='u'||c.charAt(i)=='U'){
                System.out.println(Character.toUpperCase(c.charAt(i)));
                    }
                }
            }
            break;
        }
        case 2:{
        System.out.println("Exiting.");
        torun=false;
        break;
        }
        default:{
            System.out.println("Wrong input...");
            break;
        }
    }
}
}
}

 

 

%d bloggers like this: