我试图让 if else if 语句进行操作,但在使用它时出现错误,请参阅下面的程序,谢谢
public class Info {
public static void main(String [] args){
Scanner input=new Scanner(System.in);
System.out.print("Enter employee num");
int e_num=input.nextInt();
System.out.print("Enter employee first name");
String e_fname=input.next();
System.out.print("Enter employee surname");
String e_sname=input.next();
System.out.print("Enter employee code C or c,H or h and F or f");
char e_code = input.next().charAt(0);
if(e_code==F||e_code==f){
e_code==monthly_paid;
}
}
}
最佳答案
我怀疑您只是在寻找字 rune 字来比较您的变量:
if (e_code == 'F' || e_code == 'f')
(间距不是必需的 - 只是为了便于阅读......)
另一方面,鉴于您有一组固定的选项,您很可能需要一个 switch/case。
但这看起来并不理想:
e_code==monthly_paid;
这里的monthly_paid
是什么?为什么要将代表用户输入的代码的变量更改为听起来像金额的变量?
关于java - 如何根据我输入的字符进行 if else 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13859611/