Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在J2ME中获得int[]的最大值?_Java_Java Me - Fatal编程技术网

Java 如何在J2ME中获得int[]的最大值?

Java 如何在J2ME中获得int[]的最大值?,java,java-me,Java,Java Me,有一个int[]变量,例如private int[3]tInt=new int[]{6,9,4} 在本例中,9是最大值 那么如何编写一个J2ME代码来获取Int[]的最大值呢?Int max=Integer.MIN_value;//或最大值=色调[0] int max = Integer.MIN_VALUE; // or max = tInt[0] for (int i = 0; i < tInt.length; i ++) { if (tInt[i] > max) {

有一个int[]变量,例如
private int[3]tInt=new int[]{6,9,4}

在本例中,
9
是最大值

那么如何编写一个J2ME代码来获取Int[]的最大值呢?

Int max=Integer.MIN_value;//或最大值=色调[0]
int max = Integer.MIN_VALUE; // or max = tInt[0]
for (int i = 0; i < tInt.length; i ++) {
    if (tInt[i] > max) {
       max = tInt[i];
    }
}

System.out.println("Max is: " + max);
对于(int i=0;i最大值){ 最大值=色调[i]; } } System.out.println(“最大值为:+Max”);
您可以看到一些第三方库。您不太可能在JavaME中使用它们,但只是为了完整性(它们使用与上面相同的代码)

  • 番石榴:
    Ints.max(色调)
  • 通用语言:
    numberrutils.max(色调)
int max=Integer.MIN\u值;//或最大值=色调[0]
对于(int i=0;i最大值){
最大值=色调[i];
}
}
System.out.println(“最大值为:+Max”);
您可以看到一些第三方库。您不太可能在JavaME中使用它们,但只是为了完整性(它们使用与上面相同的代码)

  • 番石榴:
    Ints.max(色调)
  • 通用语言:
    numberrutils.max(色调)
max=0;
for(int i=0;i
max=0;
for(int i=0;i
假定最大值为正值。需要
max=Integer。最小值假定最大值为正值。需要
max=Integer.MIN_VALUE
这是人们开始学习CS时首先要学习的算法之一这是人们开始学习CS时首先要学习的算法之一
max = 0;

            for (int i = 0; i < array.length; i++) 
            {
                if(max < array[i])
                {
                   max = array[i]; 
                }
            }