Write a Java method isAverageInRange
时间: 2024-06-04 16:11:52 浏览: 10
public static boolean isAverageInRange(int[] array, int lowerBound, int upperBound) {
if(array.length == 0) {
return false;
}
double sum = 0;
for(int i = 0; i < array.length; i++) {
sum += array[i];
}
double average = sum / array.length;
return average >= lowerBound && average <= upperBound;
}
// This method takes an array of integers and two integer bounds as input parameters,
// and returns true if the average of the integers in the array is within the range
// specified by the two bounds (inclusive), and false otherwise. If the array is empty,
// the method returns false.
相关问题
Write a java program to convert char to String by using toString() method.
Sure! Here's a sample Java program to convert a char to a String using the toString() method:
```
public class CharToStringExample {
public static void main(String[] args) {
char c = 'a'; // char to convert
String str = Character.toString(c); // convert char to String using toString() method
System.out.println("Converted string: " + str);
}
}
```
Running this program will output the following:
```
Converted string: a
```
Let me know if you have any other questions!
write a three-layer loop in java
Java 中三层循环的代码如下:
```
for (int i = 0; i < outerLoopLimit; i++) {
for (int j = 0; j < middleLoopLimit; j++) {
for (int k = 0; k < innerLoopLimit; k++) {
// Do something here
}
}
}
```
请注意,在代码中,`outerLoopLimit`,`middleLoopLimit` 和 `innerLoopLimit` 是循环的次数限制,可以根据需要替换为任何值。在循环体内的 `// Do something here` 注释行表示在循环内执行的代码,请将其替换为实际代码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)