大家好,今天小编关注到一个比较有意思的话题,就是关于java语言怎么编写数组的问题,于是小编就整理了3个相关介绍Java语言怎么编写数组的解答,让我们一起看看吧。
JAVA怎么求数组的最大值和最小值?
错在最后两段代码是相同的,写了两个“max”,就会得到最大值与最小值是一样的结果。
只需要把最后一个“max”改为“min”就可以了,改了之后的程序如下:
public class a {
public static void main(String args[]) {
int a[]={84,40,16,3,10,49,28,76,94,70};
int n;
int min=a[0];
int i;
int max=a[0];
for(n=0;n<=9;n++) {
怎么new一个对象数组j***a?
首先我们需要创建一个class:
class Student{ String name; double score; String num; Student(String n,double s,String m){ name=n; s=score; num=m; } public static void printInfo(){ System.out.println(num+","+name+","+score); } }
接下来我们对此类进行数组的创建:
//1 Student stu[];<span > </span>//声明数组。 stu=new Student [3];<span > </span>//创建数组,这里是创建的一个引用的数组,每一个引用并没有确切的地址。 for(int i=0;i<3;i++){<span > </span>//为数组创建对象,也就是说为创建的引用关联到确切的地址。 stu[i]=new Student(); } //2 Student stu[]=new Student [3]; for(int i=0;i<3;i++){ stu[i]=new Student(); } //3 Student stu[]=new Student{new Student(sjl,87,01),new Student(ljs,98,02),new Student(lls,92,03)};
J***AString数组?
J***a数组是在J***a编程中经常使用的一个类,下面是对J***a数组String的使用方法:
1、J***a数组的: String[数组下标], J***a数组的下标是从0开始的。
2、获取数组中的所有元素,会用到数组的遍历,通常用for循环。
5、可以使用Arrays类中binarySearch(Object[] a, Object key) 方法来查找是否存在某个值。
到此,以上就是小编对于j***a语言怎么编写数组的问题就介绍到这了,希望介绍关于j***a语言怎么编写数组的3点解答对大家有用。