多组输入,每行输入一个字母。
针对每组输入,输出为一行,如果输入字母是元音(包括大小写),输出“Vowel”,如果输入字母是非元音,输出“Consonant”。
A b
Vowel Consonant
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String a = in.nextLine(); switch (a.toLowerCase()) { case "a" : System.out.println("Vowel"); break ; case "e" : System.out.println("Vowel"); break ; case "i" : System.out.println("Vowel"); break ; case "o" : System.out.println("Vowel"); break ; case "u" : System.out.println("Vowel"); break ; default: System.out.println("Consonant"); } } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] letters={"a","e","i","o","u"}; String type=""; while(sc.hasNextLine()){ String letter=sc.nextLine().toLowerCase(); for(String l:letters){ if(l.equals(letter)){ type="Vowel"; break; }else{ type="Consonant"; } } System.out.println(type); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); char ch; while(in.hasNext()) //表示是否将要有输入 { /*输入字符串再取第一个字符 (用字符串是因为没有nextChar()函数)*/ ch=in.next().charAt(0); //将字符统一转换为大写的,这样可以少写些判断条件 ch=Character.toUpperCase(ch); //判断语句 if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') { System.out.println("Vowel");//是元音时输出 } else{ System.out.println("Consonant");//是辅音时输出 } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = "AEIOUaeiou"; while(scanner.hasNext()){ char toJudge = scanner.next().charAt(0); int contant = str.indexOf(toJudge); if(contant >-1){ System.out.println("Vowel"); }else{ System.out.println("Consonant"); } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = "AOEIUaoeiu"; while (sc.hasNext()) { char a = sc.next().charAt(0); int l = str.indexOf(a); if (l>-1) { System.out.println("Vowel"); } else { System.out.println("Consonant"); }} } }
import java.util.*; public class Main{ public static void main(String args[]){ Scanner input=new Scanner(System.in); while(input.hasNextLine()){ String temp=input.nextLine(); if(temp.charAt(0)=='A'|temp.charAt(0)=='a'|temp.charAt(0)=='E'|temp.charAt(0)=='e'|temp.charAt(0)=='I'| temp.charAt(0)=='i'|temp.charAt(0)=='O'|temp.charAt(0)=='o'|temp.charAt(0)=='U'|temp.charAt(0)=='u'){ System.out.println("Vowel"); } else System.out.println("Consonant"); } } }
import java.util.Scanner; /** * * @Title 判断是元音还是辅音 * @Description KiKi开始学习英文字母,BoBo老师告诉他,有五个字母A(a), E(e), I(i), O(o),U(u)称为元音,其他所有字母称为辅音,请帮他编写程序判断输入的字母是元音(Vowel)还是辅音(Consonant)。 * 输入描述: * 多组输入,每行输入一个字母。 * 输出描述: * 针对每组输入,输出为一行,如果输入字母是元音(包括大小写),输出“Vowel”,如果输入字母是非元音,输出“Consonant”。 * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/16 10:41 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()) { String s = in.nextLine(); int i = "AaEeIiOoUu".indexOf(s); if(i > -1) { System.out.println("Vowel"); } else { System.out.println("Consonant"); } } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()){ String str = scanner.nextLine(); char ch = str.charAt(0); if (ch == 'A' || ch == 'a'||ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){ System.out.println("Vowel"); }else { System.out.println("Consonant"); } } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = "AaEeIiOoUu"; while(sc.hasNext()){ String s = sc.next(); if(str.contains(s)) System.out.println("Vowel"); else System.out.println("Consonant"); } } }
只要有元素就匹配,不管是否出现其他元素import java.util.Scanner; import java.util.regex.Pattern; public class Test46 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); while(input.hasNext()) { String c=input.nextLine(); if(Pattern.compile(c,Pattern.CASE_INSENSITIVE).matcher("aeiouAEIOU").find()) System.out.println("Vowel"); else System.out.println("Consonant"); } } }
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("A"); list.add("E"); list.add("I"); list.add("O"); list.add("U"); Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ String s = scanner.next(); if(list.contains(s.toUpperCase())){ System.out.println("Vowel"); }else{ System.out.println("Consonant"); } } } }
import java.io.*; public class Main{ public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=""; char c; while((str=br.readLine())!=null) { c=str.charAt(0); switch (c){ case'a': case'e': case'i': case'o': case'u': case'A': case'E': case'I': case'O': case'U': System.out.println("Vowel"); break; default: System.out.println("Consonant"); } } } }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String s=sc.next(); if(s.matches("[AEIOUaeiou]")) { System.out.println("Vowel"); } else { System.out.println("Consonant"); } } } }