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 6830019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:34:07+00:00 2026-05-26T22:34:07+00:00

I am writing a simple start-up java program. The problem I am facing is

  • 0

I am writing a simple start-up java program. The problem I am facing is that the company name is not being added properly.

public class Company {
    public static BufferedReader br;
    public static BufferedReader br1;
    public static String numberOfCompanies;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        CompanyDetails qw = new CompanyDetails();

        try{
            //Scanner in = new Scanner(System.in);
            br = new BufferedReader(new InputStreamReader(System.in));
            br1 = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter number of companies: ");
            numberOfCompanies = br.readLine();
            int G = Integer.parseInt(numberOfCompanies);

            for (int i = 1; i <= G; i++) {
                qw = new CompanyDetails();
                System.out.println("Enter name of the company: ");
                String company = br1.readLine();
                qw.company(company, i);
            }
            for (int i = 0; i <= G; i++) {
            qw.companySummary(G);
            }
        } catch (IOException io) {
            io.printStackTrace();
        }

    }   
}

class CompanyDetails {
    String company, name;
    public String input;
    public static BufferedReader br;
    public double iE;
    public static String numberOfCompanies;
    String nameOfCompany;
    String[] nameofCompany1 = new String[100];
    int ir,i,employee;
    ArrayList<String> bulk = new ArrayList<String>();

    public String[] company(String input, int i) {
        // TODO Auto-generated method stub
        //ArrayList bulk = new ArrayList();
        //for(int ith = i; ith<= 2; i++){
        nameOfCompany = i+input;
        bulk.add(nameOfCompany);
        bulk.add(nameOfCompany);
    //  }
        return nameofCompany1;
    }

    public void employee(double d) {
        // TODO Auto-generated method stub
        ir = (int)d;
    }

    public void companySummary(int G) {

        System.out.println("Number of companies: " + G);
        System.out.println("Name of company: " +bulk +" ");
        System.out.println("Number of employees: "+ir); 
    }   
}

The output I am getting is

enter image description here

Why aren’t I getting 234 at the position 1 of the arraylist ??

  • 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-26T22:34:08+00:00Added an answer on May 26, 2026 at 10:34 pm

    You are creating a new CompanyDetails object in each iteration of the loop, there by loosing your earlier object:

    for (int i = 1; i <= G; i++) {
       qw = new CompanyDetails();
    

    You are already creating an CompanyDetails object at the start of main method:

    CompanyDetails qw = new CompanyDetails();
    

    So you don’t have to do it again in the for loop.

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

Sidebar

Related Questions

Alright, so I'm writing this program that essentially batch runs other java programs for
I am writing a simple application in Java that does some particle simulation on
I'm writing a simple timer in Java. It has Start and Stop buttons, along
I am trying to start writing some simple jQuery plugins and for my first
I'm writing simple program to communicate between smart devices and I receive 11001 when
I am writing simple site that requires users and profiles to be handled. The
I'm writing a simple OpenGL application that uses GLUT . I don't want to
I'm writing a simple app that's going to have a tiny form sitting in
I am currently writing a simple, timer-based mini app in C# that performs an
I am writing a simple checkers game in Java. When I mouse over the

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.