2016-11-28 28 views
-4
public static void main(String[] args) { 
    Scanner Input= new Scanner(System.in); 
    System.out.print("Enter String: "); 
    String s =Input.nextLine(); 
    int index = s.length(); 
    boolean isVowel= true; 
    isVowel = vowels(s,index); 
    if(isVowel==true) 
     System.out.println("Its Vowel"); 
} 
public static boolean vowels(String s,int index){ 
    String small=s.toLowerCase(); 
    String large = s.toUpperCase(); 
    char z=s.charAt(s.length()-1); 
    if (s==small) { 
     large = s.toUpperCase(); 
     if(s==large){ 
     } 
     for (int i = 0; i < s.length(); i++) { 
      if (z=='A'||z=='E'||z=='I'||z=='O'||z=='U') { 
       System.out.println("Character at " + s.charAt(s.length()-1) + " is a vowel"); 
       return true; 
      } else if(z!='A'||z!='E'||z!='I'||z!='O'||z!='U'){ 
       System.out.println("The String contains no Vowels");  
       return false; 
      } 
     } 
    } 
    return true; 
    } 
} 

它一直返回最后一个打印语句“字符串不包含元音” 有什么建议吗?检查字符串中元音的方法

+0

请格式化您的代码并正确解释您的问题。阅读http://stackoverflow.com/help/how-to-ask – StackFlowed

+0

你想要的输出是什么? –

+1

逐句通过您的代码,我们不是一个调试服务。 –

回答

-1
import java.util.*; 

public class Solution{ 
    public static void main(String[] args) { 
     Scanner Input= new Scanner(System.in); 
     System.out.print("Enter String: "); 
     String s =Input.nextLine(); 
     if(vowels(s)) System.out.println("It contains a vowel!"); 
     else System.out.println("It does not!"); 
    } 
    public static boolean vowels(String s){ 
     String word = s.toUpperCase(); 
     char[] words = word.toCharArray(); 
     for(int i = 0; i<words.length; i++){ 
      char z = words[i]; 
      if (z=='A'||z=='E'||z=='I'||z=='O'||z=='U') return true; 
     } 
     return false; 
    } 

} 

如果我理解你的问题的权利,我认为上面的代码应该这样做。

相关问题