Java 比较同一数组中的元素

Java 比较同一数组中的元素,java,Java,我有这个阵列: int[]次={341、273、278、329、445、402、388、275、243、334、412、393、299、343、317、265、345、360、423} 我需要比较这些元素,找出并输出最大的数字。我正在使用java。我正在帮助的任何方式,因为您对编程完全是新手 参考 不要每次都期待这种帮助: public class FindMax { public static void main(String[] args) { int[] time

我有这个阵列:

int[]次={341、273、278、329、445、402、388、275、243、334、412、393、299、343、317、265、345、360、423}


我需要比较这些元素,找出并输出最大的数字。我正在使用java。

我正在帮助的任何方式,因为您对编程完全是新手 参考 不要每次都期待这种帮助:

public class FindMax {

    public static void main(String[] args) {
        int[] times ={ 341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265, 345, 360, 423 };
        System.out.println("Max Element: "+ findMax(times));
    }
    //method which takes input as an array of integers and returns max integer
    public static int findMax(int[] nums){
        int max=nums[0];
        for(int num :nums){
            if(max<num){
                max=num;
            }
        }
        return max;
    }


}

这是一项有趣的任务。为什么你觉得你必须和我们分享它?谷歌搜索的想法:如何在java中比较整数,如何在javaOff主题中打印出来,因为这不是一个真正的问题。