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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:46:15+00:00 2026-06-13T22:46:15+00:00

I have recently learned about Setters and Getters. I can use them but the

  • 0

I have recently learned about Setters and Getters. I can use them but the problem is that I have to use them in a loop. Some of the code that I am using is mentioned below.

I am entering Student information in a loop, and then editing it in another loop using Set Get methods. I can use the setter and getter methods without the loop but I am not sure how to use them inside the loop. So please guide me to add students in a stu array.

    public static void   Addstudents()
    {   
      for(int i=0; i<stu.length; i++)
      {
        stu[i]=new Stuinfo();
        System.out.println("Enter name ");
        name= sc.next();
        System.out.println("Enter id  ");
        id= sc.next();
      }
    }

And to edit the data, I want to run a loop and use the setter method to set the values. Something like this:

  public void Modify()
  { 
    String Cid; 
    System.out.println("You r modifying account");
    for (int i=0; i<stu.length;i++)
    { 
      stu[i].setId(id)...// dont know what to do in loop hree 
    }
  }
  • 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-06-13T22:46:16+00:00Added an answer on June 13, 2026 at 10:46 pm

    The question is not clear, I think that to modify a specific account of a single student, you need something like this :

       public void Modify() {   
        String Cid; 
        System.out.println("Enter your ID :");
        Scanner sc = new Scanner(System.in);
        int id = sc.nextInt();
    
        for (int i=0; i<stu.length;i++)
        {   
               if(id == stu[i].getId()) {
                //Change your account details
                System.out.println("Enter name ");
                 name= sc.next();
                 stu[i].setName(name);
                }
    
        }
         }
    

    In the example above, you are getting an id as input, and then you are looking up in the array for the input id, and if you find one, you are giving the opportunity to the user to change the account details of that specific user …

    While in the first example you have to set your students instance properties using setters :

     public static void   Addstudents()
         {
    
         for(int i=0; i<stu.length; i++)
        {
        stu[i]=new Stuinfo();
        System.out.println("Enter name ");
        stu[i].setName( sc.next() );
        System.out.println("Enter id  ");
        stu[i].setId( sc.next() ); 
    
    
        }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently learned that you can use a neat switch statement with fallthrough
I have recently learned to create dynamic links via php, but my problem today
I have recently learned that sql server 2005 does not support UTF8: UTF8 problem
I recently learned about code obfuscation. Its nice thing to do, when you have
I've recently learned that python doesn't have the switch/case statement. I've been reading about
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I have learned recently that Export in Mathematica uses by default the Printout screen
I have recently learned about continuous integration. From my understanding, its a way to
I'm recently have learned to use Zend Framework. I did a simple CRUD application.
I've recently learned that i shouldn't store html encoded data in the database, but

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.