importjava.util.Scanner;publicclassJAV{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);Personps[]=newPerson[3];//从键盘输入三个person的信息for(inti=...
import java.util.Scanner;
public class JAV {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Person ps[] = new Person[3];
//从键盘输入三个person的信息
for(int i=0 ; ips[i] = new Person();
//输入数据
System.out.println("请输入名字");
String n = input.next();
System.out.println("请输入年龄");
int a = input.nextInt();
ps[i].setName(n);
ps[i].setAge(a);
}
//设置属性值
//输出年龄最大人的信息
//按照年龄进行从小到大的排序输出
//调用每个对象的info方法
for(int i=0; i
Person p = ps[i];
p.info();
}
}
}
中如何调用这个方法
import java.util.Scanner;
public class Paixun {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int setAge[]= new int[3];
setAge[0] = input.nextInt();
setAge[1] = input.nextInt();
setAge[2] = input.nextInt();
for(int i=0;i
for(int j=i+1;j
if(setAge[i]>setAge[j]){
int tmp = setAge[j];
setAge[j] = setAge[i];
setAge[i] = tmp;
}
}
}
for(int i:setAge){
System.out.println("i="+i);
}
}
public void info()
{
System.out.println("input.nextInt");
}
}
展开