请帮我解决关于数组的Java作业 [英] Please help me solve my Java homework about arrays

查看:83
本文介绍了请帮我解决关于数组的Java作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述:


给定一个整数数组,计算数组是否包含某个值的值在数组中,该值乘以10.我们将使用仅考虑从给定索引开始的数组部分的约定。初始调用将在索引中传递为0.

Given an array of ints, compute if the array contains somewhere a value followed in the array by that value times 10. We'll use the convention of considering only the part of the array that begins at the given index.The initial call will pass in index as 0.

示例:

public boolean array220(int [] nums,int index)


array220({1,2,20},0)→true

array220({3,30},0)→true

array220({3},0)→false **

array220({1, 2, 20}, 0) → true
array220({3, 30}, 0) → true
array220({3}, 0) → false**

我遇到问题而无法解决问题。

I'm stuck with the problem with no approach to solve it.

推荐答案

for (int i = index; i < nums.length - 1; i++) 
    if (nums[i] * 10 == nums[i + 1]) return true;
return false;

这篇关于请帮我解决关于数组的Java作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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