算法训练 6-3判定字符位置

Posted watchfree

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了算法训练 6-3判定字符位置相关的知识,希望对你有一定的参考价值。

算法训练 6-3判定字符位置  
时间限制:1.0s   内存限制:512.0MB
    
  返回给定字符串s中元音字母的首次出现位置。英语元音字母只有‘a’、‘e’、‘i’、‘o’、‘u’五个。
  若字符串中没有元音字母,则返回0。
  只考虑小写的情况。
样例输入
and
样例输出
1
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
        String str=sc.next();
        int ans=0;
        for(int i=0;i<str.length();i++){
            char temp=str.charAt(i);
            if(temp==‘a‘||temp==‘e‘||temp==‘i‘||temp==‘o‘||temp==‘u‘){
                ans=i+1;
                break;
            }
        }
        
        System.out.println(ans);
        }

    }

}

 

以上是关于算法训练 6-3判定字符位置的主要内容,如果未能解决你的问题,请参考以下文章