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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:10+00:00 2026-06-14T12:24:10+00:00

A program that simply moves array elements. Two variables: userInputVariable and blankSpaceVariable . I

  • 0

A program that simply moves array elements.

Two variables: userInputVariable and blankSpaceVariable.

I have a 2D array named table. Defined as table[userInputVariable + 1][6]

I am printing out this array in a table format, and the far left column is numbered by whatever number the user entered at the beginning of the program.

I then ask the user where they would like to enter a blank space within the array. This blank space acts like a divider for all the other information in the array.

For example, if the user enters 10 at the start for the userInputVariable, and then enters 5 for the blank space. Once printed, the numbers should go like this:

1, 2, 3, 4, –, 5, 6, 7, 8, 9, 10.

My plan has been to create a for loop and try to move all the numbers in the array back a position starting from the blank space variable.

What I currently have, but does not work:

for (int i = blankSpaceVariable; i < table.length - 1; i++) 
{
table[i] = table[i + 1];
}
table[blankSpaceVariable] = "--";

With my current code, the numbers go like this:

1, 2, 3, 4, 6, 7, 8, 9, 10

Tried completing this a few different ways also, but the other info within my 2D array didn’t move with the numbers. So I thought that this approach can hopefully move all the info within my 2D array down, and make way for a blank section.

All help is greatly appreciated!

  • 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-14T12:24:12+00:00Added an answer on June 14, 2026 at 12:24 pm

    If you want to move numbers to the next position, then you should start from the end of the array.

    for (int i = table.length - 1; i > blankPosition; i--) {
        table[i] = table[i - 1];
    }
    table[blankPosition] = 99;
    

    From your example, it could be necesary to substract 1 from blankPosition (you say if blankPosition is 5, then the table[4] has the --), but this probably would be good to do before entering the loop (it’s a matter of formatting the data for the actual implementation).

    And probably renaming table would be a good idea, too.


    Really nasty example implementation:

    public class Arrays {
    
            public static void main(String[] args) {
                    Integer blankPosition = Integer.parseInt(args[0]);
                    // Using 99 instead of "--" because of array type
                    int[] table = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 99};
                    printEm(table);
                    for (int i = table.length - 1; i > blankPosition; i--) {
                            table[i] = table[i - 1];
                    }
                    table[blankPosition] = 99;
                    printEm(table);
            }
    
            public static void printEm(int[] array) {
                    for(int i = 0; i < array.length; i++) {
                            System.out.print(array[i] + " ");
                    }
                    System.out.println();
            }
    }
    

    Let’s run it:

    $ java Arrays 5
    1 2 3 4 5 6 7 8 9 10 99 
    1 2 3 4 5 99 6 7 8 9 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a program that moves certain named folders (and all files
I have a program where an entity moves around in two-dimensional space. To move
In C#, is there a way to make a program that simply eats roughly
I need to build a content gathering program that will simply read numbers on
I have a simple program that checks webpages for strings, example: Private Sub Button1_Click(ByVal
I have this simple program that computes salaries for four different worker types. It's
Say I have simple program that emulates a board game with a number of
I have a simple program that creates a thread, loops twenty times and then
I have a simple program that reads data from a PNG into a 2D
I have written a simple program that does autocorrelation as follows...I've used pgi accelerator

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.