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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:53:37+00:00 2026-06-05T13:53:37+00:00

I have a program that accepts a number that represents an array index and

  • 0

I have a program that accepts a number that represents an array index and a
String to replace the array element corresponding to the index.

Here is my code:

public static void main(String args[]){

    String names[]={"Alvin", "Einstein", "Ace", "Vino", "Vince"};

          for(int i=0; i<names.length;i++)
                 System.out.println(i + " - " + names[i]);

    replaceArrayElement(names);
}

   public static void replaceArrayElement(String name[]){

       int index = 0;
       String value = "";

       Scanner scan = new Scanner(System.in);

       System.out.print("\nEnter the index to be replaced:");
       index = scan.nextInt();

       if(index<name.length){

           System.out.print("Enter the new value:");
           value = scan.nextLine();

           name[index] = scan.nextLine(); 

           System.out.println("\nThe new elements of the array are");

           for(int j=0; j<name.length;j++)
               System.out.println(name[j]);
       } 
       else{     
            System.out.println("Error!");    
       }  
   }

What I need to do is to put the int index variable and String value variable inside the method replaceArrayElement as a parameters. But I don’t know how to call a method with different data type parameters. Can somebody show me how?? Thank you.

  • 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-05T13:53:39+00:00Added an answer on June 5, 2026 at 1:53 pm

    Well it’s not clear where you’d get the values to pass in from, but here’s how you would declare the method:

    public static void replaceArrayElement(String[] name, int index, String value)
    

    You’d call it with:

    // Get the values from elsewhere, obviously
    replaceArrayElement(array, 5, "fred");
    

    Note that I’ve used String[] name instead of String name[] – while the latter syntax is permitted, it’s strongly discouraged as a matter of style.

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

Sidebar

Related Questions

I have made a little program in java that accepts a string as a
I have a very simple question. I have a program that accepts an integer
I have program that runs fast enough. I want to see the number of
I have a program that looks something like this: public partial class It {
I have a program that has this code : #include<stdio.h> main(){ int input; char
I have a program that accepts a Cmd command as a command argument. Basically
I have a function that accepts a message in String form. The message looks
I have a Java program that creates a server socket and accepts connections from
I need help here in my practice program. I have a json array: myData=[{plank_number:1,thickness:5,width:7,length_t:8,quantity:1},
I have a function that accepts a large array of x,y pairs as an

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.