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

It keeps returning the last printing statement, "The String contains no Vowels" Any suggestions?

RaminS
  • 2,208
  • 4
  • 22
  • 30
Danial Nawab
  • 3
  • 1
  • 4

1 Answers1

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

}

If I understood your question right, I think the above code should do it.

rishran
  • 596
  • 2
  • 7
  • 26