java - 如何根据我输入的字符进行 if else 操作

标签 java

我试图让 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/

相关文章:

java - Hibernate session.get() 显示空

Java/Ruby : is there a way to do . 在 Java 中常量化或 Object.send()?

java - C/C++ 是否有 Findbugs 和/或 PMD 等价物?

java - 从 android webview 打开视频播放器而不是在常规 <a> 上打开它

java - 如何以编程方式在 eclipse 中添加我自己的 checkstyle?

java - 从常规列表中删除特定值

java - Android Studio : Read in a text file, 在弹出窗口中显示

java - 为什么 getEdgeFlags() 总是返回 0

java - SQLiteOpenHelper onUpgrade 被多次调用

java - 无法为元素 RollingFile 创建 org.apache.logging.log4j.core.appender.RollingFileAppender 类型的插件