Use string in switch case in java

前端 未结 13 1663
盖世英雄少女心
盖世英雄少女心 2020-12-01 07:30

I need to change the following if\'s to a switch-case while checking for a String, to improve the cyclomatic complexity.<

相关标签:
13条回答
  • 2020-12-01 08:00
        String name,lname;
     name= JOptionPane.showInputDialog(null,"Enter your name");
       lname= JOptionPane.showInputDialog(null,"Enter your father name");
        if(name.equals("Ahmad")){
           JOptionPane.showMessageDialog(null,"welcome "+name);
        }
        if(lname.equals("Khan"))
       JOptionPane.showMessageDialog(null,"Name : "+name +"\nLast name :"+lname ); 
    
        else {
           JOptionPane.showMessageDialog(null,"try again " );
        } 
      }}
    
    0 讨论(0)
提交回复
热议问题