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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:26:06+00:00 2026-05-14T20:26:06+00:00

What is wrong here? I want delete an item from an array, but it

  • 0

What is wrong here? I want delete an item from an array, but it shows me

error ArrayIndexOutBound exception

public class delete {

    public static void main(String[]args) {
        int i;

        //delete  item from array
        int k[] = new int[]{77,99,44,11,00,55,66,33,10};

        //delete 55
        int searchkey=55;

        int nums=k.length;
        for ( i=0;i<nums;i++)
            if (k[i]==searchkey)
                break;

        for (int t=i;t<nums;t++)
            k[t]=k[t+1];
        nums--;

        for (int m=0;m<nums;m++) {
            System.out.println(k[m]);
        }
    }
}
  • 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-14T20:26:06+00:00Added an answer on May 14, 2026 at 8:26 pm

    The following rewriting should be instructive:

    public class Delete {
        static int search(int key, int[] arr) {
            for (int i = 0; i < arr.length; i++)
                if (arr[i] == key) {
                    return i;
                }
            return -1;
        }
        static void print(int[] arr, final int L) {
            for (int i = 0; i < L; i++) {
                System.out.println(arr[i]);
                // try this also:
                // System.out.format("%02d ", arr[i]);          
            }
        }
        public static void main(String[] args) {
            int nums[] = { 77, 99, 44, 11, 00, 55, 66, 33, 10 };
            final int N = nums.length;
            int searchKey = 55;
    
            int pos = search(searchKey, nums);
            for (int t = pos; t < N-1; t++) {
                nums[t] = nums[t + 1];
            }
            print(nums, N-1);
            // prints 77, 99, 44, 11, 0, 66, 33, 10
            System.out.println(010 == 8); // prints "true"
            System.out.println(00000); // prints "0
        }
    }
    

    Here are some key observations:

    • Break apart logic into helper methods. This makes the logical components easier to test and reuse, and the overall logic easier to understand.
    • It makes the code easier to understand if you use final local variables like N to denote the initial size of int[] nums, and define the rest of the logic in terms of N, N-1, etc.
      • The more non-final variables there are, the harder it is to understand what’s going on as their values changes over time
    • Follow coding convention. In particular, class names starts with uppercase.
    • Do be careful with the 00 in the array. The 0 prefix is for octal literals. That is, 010 == 8.
    • Do note that 00 is printed as simple 0. Numerically, 00 = 000 = 0000 = 0. If you need this to be zero-padded, then that’s a formatting issue.

    See also

    On octal literals

    • 09 is not recognized where as 9 is recognized
    • Integer with leading zeroes

    On zero-padding

    • Left padding integers with zeros in Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 408k
  • Answers 408k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Doesn't look like you can do it with Net:HTTP. Here's… May 15, 2026 at 6:53 am
  • Editorial Team
    Editorial Team added an answer The only way to get started would be to pick… May 15, 2026 at 6:53 am
  • Editorial Team
    Editorial Team added an answer You timezone string is formulated incorrectly. Try this, String sign… May 15, 2026 at 6:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.