This is the error message I get: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 7     at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)     at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)     at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)     at java.base/java.util.Objects.checkIndex(Objects.java:359)     at java.base/java.util.ArrayList.get(ArrayList.java:427)     at radixsort.RadixSort.radixSort(RadixSort.java:82)     at radixsort.RadixSort.main(RadixSort.java:26) Code: package radixsort; public class RadixSort {     public static void main(String[] args) {                 // Create a new list         int[]mylist = new int[100];                  // Loop that iterates for the entire list of elements         for(int i=0; i[]newbucket=new java.util.ArrayList[10];                                  // Loop that iterates for the list of elements                 for(int i=0; i();                     }                                      // Loop that iterates for the number of digits                     for (int position = 0; position<=digit_count; position++)                     {                                                  // Loop that iterates to clear the bucket                         for(int i=0; i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This is the error message I get:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 7
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
    at java.base/java.util.Objects.checkIndex(Objects.java:359)
    at java.base/java.util.ArrayList.get(ArrayList.java:427)
    at radixsort.RadixSort.radixSort(RadixSort.java:82)
    at radixsort.RadixSort.main(RadixSort.java:26)

Code:

package radixsort;


public class RadixSort {

    public static void main(String[] args) {
       
        // Create a new list
        int[]mylist = new int[100];
        
        // Loop that iterates for the entire list of elements
        for(int i=0; i<mylist.length; i++)
            
            // Create a random numbers
            mylist[i]= (int)(Math.random()*1000);
        
            // Perform Sort
            radixSort(mylist,3);
            
            // Loop that interates over the entire elements
            for(int i=0; i<mylist.length; i++)
                
                // Display the elements
                System.out.print(mylist[i]+"");
                }
    
                // Method definition to sort the elements
                public static void radixSort(int[]list, int digit_count)
                {
                    
                // Create the new bucket
                java.util.ArrayList<Integer>[]newbucket=new java.util.ArrayList[10];
                
                // Loop that iterates for the list of elements
                for(int i=0; i<newbucket.length; i++)
                {
                    // Add elements into the bucket
                    newbucket[i]= new java.util.ArrayList<Integer>();
                    }
                
                    // Loop that iterates for the number of digits
                    for (int position = 0; position<=digit_count; position++)
                    {
                        
                        // Loop that iterates to clear the bucket
                        for(int i=0; i<newbucket.length; i++)
                        {
                                
                        // Clear the bucket
                        newbucket[i].clear();
                        }
                    
                        // Loop that iterates to distribute the elements into the bucket
                        for(int i=0; i<list.length; i++)
                        { 
                        // Position the bucket
                        int key = getKey(list[i],position);
                        
                        // Add the elements into the list
                        newbucket[key].add(list[i]);
                        }
                        
                        // Elements are moved back to the bucket
                        int k =0;
                        
                        // Loop that iterates the value of the elements
                        for(int i=0; i<newbucket.length; i++)
                        {  
                            
                         // Loop that iterates the value of the elements
                        for(int j=0; j<newbucket[i].size(); j++)
                        
                        // Add the elements into the bucket
                        list[k++]=newbucket[i].get(j);
                        }                    
                        }    
                        } 
                        // Method to return the key elements
                        public static int getKey(int number, int position)
                        {  
                        // Declare the required variables
                        int result=1;
                        // Loop that iterates to add the desired position
                        for(int i=0; i<position; i++)
                        // Calculate the result value
                        result*=10;
                        // Return the result
                        return(number/result)%10;
                        }
                        }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY