java - 我收到错误 :cannot find symbol when compiling

标签 java if-statement compiler-errors

我正在尝试使用 IF 语句进行计算和舍入,代码如下。错误出现在行上: if (partterms < 6)

   // Setup Array List for Course CU
        ArrayList<Double> coursecu = new ArrayList<Double>();
  // Read inputs for Course Units and Sum the Value
        System.out.println("Please enter Individual Course CU values, Q to quit:");
        Scanner in2 = new Scanner(System.in);
        while (in.hasNextDouble())
        {
            coursecu.add(in.nextDouble());
        } 
        double sum = 0;
        for(int i = 0; i < coursecu.size(); i++)
        {
            sum = sum + coursecu.get(i);
        }
        System.out.println();
        System.out.println("Total Credit Units Required for Graduation");
        System.out.println(sum);
  // Calculate the Number of Terms to Completion
       {
          double fullterm = sum / planned_units; // Sets Whole Terms 
          double partterm = sum % planned_units; // Sets Partial Terms
        }
        if (partterm < 6)
        {
            number_terms = fullterms++;
        }
        else
        {
            number_terms = fullterms;
        }

最佳答案

{ ← 
    double fullterm = sum / planned_units; // Sets Whole Terms 
    double partterm = sum % planned_units; // Sets Partial Terms
} ←

删除 {},变量将在这个奇怪的 block 之外被识别。

关于java - 我收到错误 :cannot find symbol when compiling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20938541/

相关文章:

java - 如何在 EclipseLink 中级联 @JoinFetch?

javascript - 如何从javascript中的spring Controller 类获取值?

delphi - 常量 `array of cardinal` 产生错误 'Constant expression violates subrange bounds"

compiler-errors - 为什么临时变量会抑制 "type ascription is experimental"错误?

java - 读取对话框中的用户选择

java - 在方法内声明 HashMap

wordpress - 是否可以在 WordPress 中测试空术语或类别?

r - 使用 ifelse 的函数不返回 R 中的向量

Python 3 如果不是条件简化

objective-c - 从 Swift 调用 Objective C setter 方法时“没有成员”