I have to find out how many times the
createPerson()
function is called
This is my Main.java file
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException{
int i;
Student[] totalStudents = new Student[10];
Student.create3Persons();
Student.create2Persons();
}
}
this is my student.java file
import java.io.*;
public class Student {
private static void createPerson() throws IOException{
int number=0;
File file = new File("arg.txt", null);
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
FileInputStream fis = new FileInputStream(file);
DataInputStream dis = new DataInputStream(fis);
while(dis.readInt()!= -1)
{
number++;
dos.writeInt(1);
}
}
static void create2Persons() throws IOException{
Student.createPerson();
Student.createPerson();
}
static void create3Persons() throws IOException{
Student.createPerson();
Student.createPerson();
Student.createPerson();
}
}
What is wrong in this code?