Hi guy I'm a beginner of android studio. now I try to create for loop code but it errror and said
Process 'command 'C:/Program Files/Android/Android Studio/jre/bin/java.exe'' finished with non-zero exit value 1
and this's my code
public class FindOldestStudent {
//static Scanner console = new Scanner(System.in);
public static void main ( String [ ] args ) {
String name, tel, school;
int age;
Student[ ] student = new Student[2];
Student oldestStudent;
for (int i = 0; i < 2 ; i++) {
student[i] = new Student( );
int a = 0;
student[a] = new Student();
System.out.print(i+1 + ".Enter student name: ");
name = args[a];
student[a].setName(name);
System.out.print(name);
System.out.print(" Enter student tel: ");
tel = args[a];
student[a].setTel(tel);
System.out.print(" Enter student school: ");
school = args[a];
student[a].setSchool(school);
System.out.print(" Enter student age: ");
age = Integer.parseInt(args[i]);
student[a].setAge(age);
}
oldestStudent = maxAge(student);
System.out.print(oldestStudent.getName( ) + " is the oldest student, " +
oldestStudent.getAge( ) + " years old.");
}
private static Student maxAge( Student[ ] student ) {
Student maxStudent = new Student();
for (int i = 0; i < 2 ; i++ ) {
if (student[i].getAge( ) > maxStudent.getAge( ))
maxStudent = student[i];
}
return(maxStudent);
}
}
and
class Student{
private String name, tel, school;
private int age;
public Student(String name, String tel, String school, int age) {
this.name = name;
this.tel = tel;
this.school = school;
this.age = age;
}
public Student( ) {
this.name = "";
this.tel = "";
this.school = "";
this.age = 0;
}
public void setName(String name) {
this.name = name;
}
public void setTel(String tel) {
this.tel = tel;
}
public void setSchool(String school) {
this.school = school;
}
public void setAge(int age) {
this.age = age;
}
public String getName( ) {
return (name);
}
public String getTel( ) {
return (tel);
}
public String getSchool( ) {
return (school);
}
public int getAge( ) {
return(age);
}
}
this's my code maybe it have to takes 2 agrs, but I'm not sure how to write it. so pls guide me.