二元运算符的坏操作数类型'<' first type:float second type:Object

时间:2014-11-11 11:08:49

标签: java

我想制作一个简单的Java程序,但我收到以下错误:

bad operand types for binary operator '<'
  first type:  float
  second type: Object

这是我的代码:

public static void main(String[] args) {

    ArrayList pa = new ArrayList();
    pa.add(100);
    pa.add(85);
    pa.add(80);
    pa.add(75);
    pa.add(70);
    pa.add(60);
    pa.add(50);
    pa.add(40);

    int [] pb = new int[8]; 
    pb[0] =85;
    pb[1] =80;
    pb[2] =75;
    pb[3] =70;
    pb[4] =60;
    pb[5] =50;
    pb[6] =40;
    pb[7] =30;

    float input ;
    string grade;

        if ( (input < pa.get(1) ) && (input270 >= pb270[0]) ) // this is the problem
            {   grade = "A+";   
        } 

2 个答案:

答案 0 :(得分:1)

定义您的收藏集,使其具有类型信息,而不是使用raw type

List<Integer> pa = new ArrayList<>();

答案 1 :(得分:1)

变化:

ArrayList pa = new ArrayList();

为:

ArrayList<Integer> pa = new ArrayList<>();

或者如果您愿意:

ArrayList<Float> pa = new ArrayList<>();

在不告知列表中数据的类型的情况下,它会将所有元素视为Object,并且您无法使用floatObject<进行比较操作