Issue with using switch in Java

前端 未结 5 1789
谎友^
谎友^ 2021-01-23 16:22

I can\'t figure out why it\'s always returning the value of arg1. I\'m building a weight converter.

public double convert(double arg1,int arg2,int arg3) {
    //         


        
5条回答
  •  無奈伤痛
    2021-01-23 16:50

    Nested case statements are pretty hard to read, and tough to debug. It'd be a better idea to encapsulate the functionality you need into a method call instead.

    That being said, there's no break statement anywhere in your switch. Regardless of the case, it will fall through to the last case (setting answer equal to the bottom of the case).

提交回复
热议问题