gpt4 book ai didi

java - 关于静态方法的问题

转载 作者:行者123 更新时间:2023-12-02 00:42:51 25 4
gpt4 key购买 nike

该问题要求用户输入。让我们忘记这一点并让它已经用一些值初始化,这样我就可以理解第一部分。

Write a static method public static int findMax(int[] r) which receives as a parameter an array of numbers of type int and returns the maximum value. Write a main method to test your program with array size 10 and elements entered by user.

最佳答案

无法得到您真正想要做的事情?但如果希望一个类具有静态方法,而其他类在主访问中,那么你可以这样尝试..

public class Demo {
public static void main(String[] args) {
int i = FindMaxClass.findMax(new int[10]); // pass int array
System.out.print(i);
}
}

class FindMaxClass{
public static int findMax(int[] r){
//logic to find max.
return 0; // return the max value found.
}
}

如果静态方法应该在同一个类中,那么其他答案是好的/正确的。

关于java - 关于静态方法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5848558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com