java - Vowels are not being detected? -


how find vowel in given word?

import java.util.scanner;  public class test {      public static void main(string args[])     {         scanner =new  scanner(system.in) ;         string x=a.nextline();         for(int = 0;i<x.length();i++)         {             if(x.charat(i)=='o');             system.out.println("the word has vowel o");             break;         }     } } 

the reason getting output "when give input lets jdbc shows thisjdbc word has vowel o word has vowel o word has vowel o word has vowel o –" , if statement wrong.

when give semi colon after if statement, means executing empty statement.you can either remove semicolon after if statement ( if(x.charat(i)=='o'){-----}) or try below solution

i have modified code capture , print vowels present in given string. hope below code helps -:

public class test {      public static void main(string args[])     {         scanner =new  scanner(system.in) ;         string x=a.nextline();         for(int = 0;i<x.length();i++)         {             if((x.charat(i) == 'a') || (x.charat(i) == 'e')  ||(x.charat(i) == 'i') || (x.charat(i) == 'o') || (x.charat(i) == 'u')) {                 system.out.println("the word has vowel -: "+x.charat(i));             }         }     } } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -