Monday, 24 January 2022

A) Write a java program to display all the vowels from a given string

 Slip 2 Q 1

SAVE CODE AS   "VowelsInString.java"


import java.util.Scanner;

public class Slip2q1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a string to find vowels on it.");
String user_string = scanner.nextLine();
scanner.close();
int vowel_count = 0;
for(int i=0;i<user_string.length();i++){
if(user_string.charAt(i)=='a' ||user_string.charAt(i)=='e'
||user_string.charAt(i)=='i' ||user_string.charAt(i)=='o'
||user_string.charAt(i)=='u' ||user_string.charAt(i)=='A'
||user_string.charAt(i)=='E' ||user_string.charAt(i)=='I'
||user_string.charAt(i)=='O' ||user_string.charAt(i)=='U'){
vowel_count++;
System.out.println("Vowel found ("+user_string.charAt(i)+") at index "+i);
}
}
if (vowel_count == 0){
System.out.println("Vowel not found in given string.");
}
}
}

OUTPUT :

Write a java program to display all the vowels from a given string



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...