Skip to main content

Posts

Showing posts from April, 2023

Java Programs

  Q. Write a program to print first letters of each word in a string if it is a vowel.  Explanation: Let us consider a string "Ellen is my cousin's friend"  In the above string 'E' 'i' are first letters of string and it is vowel so it should print the two letters. Program:    import java.util.Scanner; public class Main{ public static void main(String[] args) {     Scanner sc=new Scanner(System.in);     String st=sc.nextLine();     String Words[]=st.split(" ");     for(int i=0;i<Words.length;i++){         String s=Words[i];         s=s.toLowerCase();      if(s.charAt(0)=='a'|| s.charAt(0)=='e'|| s.charAt(0)=='i'|| s.charAt(0)=='o'|| s.charAt(0)=='u'){          System.out.println(s.charAt(0));      }        } } }