java编程中的OR运算符

问题描述 投票:0回答:2

我写了这段代码来检查char是否是元音

package ifstatement;

public class IfStatement {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        char ch='a';
        if(ch==a||ch==e||ch==i||ch==o||ch==u) {
            System.out.println("It is a Vowel.");
        }
        else {
            System.out.pirntln("It is not a Vowel.");
        }
    }

}

但是我收到此错误:-

o cannot be resolved to a variable
u cannot be resolved to a variable
The method pirntln(String) is undefined for the type PrintStream

at ifstatement/ifstatement.IfStatement.main(IfStatement.java:8)
java operator-keyword
2个回答
2
投票
  • o是名为o]的变量>
  • ['o'是字符o
  • ["o"是一个字母的字符串,o
  • 您需要的是

if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')

并且pirntln

是一个错字

0
投票

您可以通过以下任意一种方式进行:

© www.soinside.com 2019 - 2024. All rights reserved.