in

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.

Java
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;
        }
    }
}
}
}

 

 

Written by Sumit Paul

Self-motivated Blogger. Very much fascinated by tech stuffs especially softwares.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

Loading…

0

Google Camera 6.2 For Mi A1

operating system assignment lpu

Design a scheduler that can schedule the processes arriving system at periodical intervals. Every process is assigned with a fixed time slice t milliseconds. If it is not able to complete its execution within the assigned time quantum, then automated timer generates an interrupt. The scheduler will select the next process in the queue and dispatcher dispatches the process to processor for execution. Compute the total time for which processes were in the queue waiting for the processor. Take the input for CPU burst, arrival time and time quantum from the user.