How to avoid 'the local variable may not have been initialized'?

后端 未结 8 1154
半阙折子戏
半阙折子戏 2020-11-27 23:00
/*This is a program that calculates Internet advertising rates based on what features/options you choose.
 * 
 *  
 */

import java.util.Scanner;

public class Inter         


        
8条回答
  •  误落风尘
    2020-11-27 23:48

    The analysis Eclipse performs to determine whether the variable is assigned on every code path isn't intelligent enough to realize that the tests on numberOfWords will never all fail. Typically, because it's not possible to statically evaluate every possible condition, a compiler/syntax checker won't attempt to evaluate any of them. If you replaced the last "else if" with an "else" it should work, as at least one assignment to textCost will occur regardless of the conditions being tested.

提交回复
热议问题