Issue with using switch in Java

前端 未结 5 1744
谎友^
谎友^ 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:45

    Other than using break, using return statements does the trick as well as it also prevents falling through cases.

    case 2: switch(arg3) { // if ounce
        case 0: return (arg1 * milligram) / milligram;
    

提交回复
热议问题