import java.util.ArrayList;
public class Averager {
private ArrayList list;
public Averager() {
list = new ArrayList();
}
public void addGrades(int test, int quiz) {
list.add(new Integer(test));
list.add(new Integer(test));
list.add(new Integer(quiz));
}
public double getAverage() {
int sum = 0;
for(int i = 0; i < list.size(); i++) {
sum += ((Integer)list.get(i)).getValue();
}
return sum/list.size();
}
}
0
A
回答
1
Integer类没有办法的getValue
3
Integer类不具备的getValue()方法。有intValue()方法。但是,对于算术运算,你甚至不必把它叫做 - Java将做autoboxing:
sum += (Integer)list.get(i);
0
sum += ((Integer)list.get(i)).intValue();
或
sum += ((Integer)list.get(i));
或
sum += (Integer.parseInt((list.get(i)).toString()));
相关问题
- 1. Android Studio中的“error:can not find symbol method”
- 2. Java错误'error:can not find symbol'
- 3. MissingSchema:URL'/'无效:未提供架构。也许你的意思是http:///?
- 4. 什么意思是“(?symbol?name)”?
- 5. error:expected';',','or')''''token .. but can not find?
- 6. Rails tests can not find test_helper
- 7. 为什么我导入一些java源文件时出现“error can not find symbol”?
- 8. ruby中的“class#method”是什么意思?
- 9. visual studio 2008 moc can not find mainwindow.h
- 10. Method =“put document:12.0.0.4518”是什么意思?
- 11. 为什么IntelliJ IDEA会为spark.sparkContext.textFile声明“Can not resolve symbol spark”?
- 12. C#搜索“你的意思是”功能
- 13. “你的意思是?”功能Lucene.net
- 14. “你的意思”在git
- 15. Try and catch method,python,indentation error can not put it out
- 16. Uncaught-TypeError-Can not-call-method-substring-of-undefined-sencha-touch-all.js
- 17. BadImageFormatException 0x80131124(Index not found)是什么意思?
- 18. 'string is not terminated'是什么意思?
- 19. can not resolve method'add(R.id.main_container,new HomeFragment())
- 20. force windbg not load symbol
- 21. Can not Longpolling Telegram
- 22. can not use cancan
- 23. Can not setImage
- 24. gcc编译器错误:“can not find -lcs50 collect2:Id returned 1 exit status”
- 25. Can not easy_install IMDbPY
- 26. Sinon not mocking method
- 27. -printf开关的find man页面解释是什么意思?
- 28. Javascript'this'value changing,but can not find out why为什么
- 29. 为什么在编译Typescript时出现“Can not find module”错误?
- 30. Can not @Autowire configuration
你甚至不给为你调用intValue,java auto-unboxes ints。它也会自动包装它们,所以不需要新的Integer。 – KitsuneYMG 2011-01-26 04:49:03