java循环 [英] java loops

查看:79
本文介绍了java循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。所以我有一个关于在循环中递增值的问题。


我的swing程序中有一个数据表。数据表有5列。在最后一列是一个整数。我希望能够在n尺寸的表格中获取所有价格。截至目前我只是通过执行以下操作来获取第一列的价格。

Hello. So i have a question regarding incrementing a value in a loop.

I have a data table in my swing program. the data table has 5 columns. In the last column is a integer. I want to be able to grab all the prices in a table of n size. as of right now i just grab the first column''s price by doing the following..

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

推荐答案

@ yeshello54


我假设getValueAt(...)方法采用行号和列号参数。如果是这样,getValueAt(i,4)从第i行获取第五列的值(整数值)。您所要做的就是使变量i遍历所有值0 ... n-1(所有'n''值)并在这些行中添加相应的列值。这样的事情:

@yeshello54
I assume that getValueAt( ... ) method takes a row number and a column number parameter. If so getValueAt(i, 4) takes the value of the fifth column (the integer value) from the i-th row. All you have to do is make variable i loop over all values 0 ... n-1 (all ''n'' values) and add the corresponding column values in those rows. Something like this:

展开 | 选择 | Wrap | 行号


谢谢。但是在尝试编译时我收到错误消息。你知道这意味着什么吗?这是我的代码
thank you. But i get an error message when trying to compile. Do you know what this means?? here is my code
展开 | 选择 | Wrap | 行号


@ yeshello54


该方法返回一个Object类型;你不能添加对象和整数。你必须明确地将它转换为Integer,如下所示:

@yeshello54

That method returns an Object type; you can''t add Objects and ints. You have to explicitly cast it to an Integer, like this:

展开 | 选择 | Wrap | 行号


这篇关于java循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆