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

问题描述

我试图for循环运行此;

I'm trying to run this for loop;

        for (int col= 0; grid[0].length; col++)

不过,我尝试编译我得到一个错误,说明每次不兼容的类型 - 发现INT但预计布尔

However every time I try to compile I get an error stating 'incompatible types - found int but expected boolean'

我不知道是什么,我做错了!

I can't work out what I'm doing wrong!

推荐答案

第二条语句:电网[0]。长度是一个整数。在fo​​r循环中第二条语句是一个条件语句,需要是一个布尔值。

the second statement: grid[0].length is an integer. The second statement in a for loop is a condition statement and needs to be a boolean.

如果你想循环而山坳低于电网的长度[0],那么你需要将此作为你的第二个语句:

If you're trying to loop while col is less than the length of grid[0], then you need this as your second statement:

&山坳LT;电网[0]。长度;

col < grid[0].length;

这篇关于Java的:for循环,不兼容的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:05