Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:32:19+00:00 2026-05-28T15:32:19+00:00

UPDATE:: OK i am putting the original problem statement here Given the Main class

  • 0

UPDATE:: OK i am putting the original problem statement here

Given the Main class create a method createPerson and call it in any other method more than once, then on the basis of the number of times the createPerson has been executed you have to initialize the objects and input names of students and output the names.

once i come to know how many objects i have to create its quite trivial to program the later part

for the prior problem of finding the number of objects to be created i have chosen the way of file handling as i come from a C, C++ background where file handling is comparatively simple.

now how should i modify the program such that i write an integer in the file, and later when i will read the file i will get the number of objects

this example forbids the use of static variable, it is a sort of brain teaser
so do Not use static

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();
    }

}

and 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();
    }
}

How should i modify this program so that i calculate how many times has been the function createPerson being called??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:32:20+00:00Added an answer on May 28, 2026 at 3:32 pm

    i got the Solution
    instead of file handling i am doing this

     static int createPerson(int c){
            return (++c);
        }
    
         static int create2Persons(int c) {
    
        return Student.createPerson(Student.createPerson(c));
        }
    
        static int create3Persons(int c) {
    
            return Student.createPerson(Student.createPerson(Student.createPerson(c)));
    
    
        }
    
    
    
    
            public static int create5Persons(int i) {
       return Student.createPerson(Student.createPerson(Student.createPerson(Student.createPerson(Student.createPerson(i)))));
            }
    

    and in the main method i have initialised an integer and i do this

     c += Student.create2Persons(i)-1;
              c += Student.create3Persons(i)-1;
              c += Student.create5Persons(i)-1;
              System.out.println(c+"c is");
    

    this saves use of files

    how to tag the thread as answered?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: When I use the subprocess.call instead of subprocess.Popen , the problem is solved
Update Putting this at the top because it is crazy :) So some users
Update : Looks like the query does not throw any timeout. The connection is
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
I'm putting together a form to create an order, where one order has many
I am constantly uploading a user control , after putting it in a update
UPDATED SOLUTION: With my particular problem, the sort call was inside a Render function
I am trying to update an Access database with a vb script by putting
I am planning on putting up a web service, or some other service exposed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.