Question
identify the line that resulted in the error message: java.lang.arrayindexoutofboundsexception. fix the line to correctly run the code
a) int[] rank=new int[10]; for(int i=0;i<=rank.length; i++){ rank[i]=i+1; w b) doublell grade= new grade[100); for(int i=-1;i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//a
   int [] rank = new int[10];
   for(int i=0;i<rank.length;i++){//modified here
   rank[i]=i+1;
   }
  
   //b
   double[] grade = new double[100];
   for(int i=0;i<grade.length;i++){//modified here
   System.out.println(grade[i]);
   }
  
   //c
   String ung ="";
   String[] campus = {"Dahlonega","Gainesville","Bluerigde","Cumming","Oconee"};
   for(int i=0;i<campus.length;i++){//modified here
   ung=ung+campus[i];
   }

Add a comment
Know the answer?
Add Answer to:
identify the line that resulted in the error message: java.lang.arrayindexoutofboundsexception. fix the line to correctly run...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are four parts for one code, all are small code segments for one question. public class StudentTest { public static void main(String[] args){ // Part Time Student Test Student ft1 = new PartTimeStudent("George", "Bush", "123-12-5678", 1, 2 ); System.out.println(ft1); Student ft2 = new PartTimeStudent("Abraham", "Lincoln", "001-90-5323", 6, 22 ); System.out.println(ft2); // Full Time Student Test Student pt1 = new FullTimeStudent("Nikola", "Tesla", "442-00-0998", 8, 26...

  • I need help with the code below. I am getting an error message I am not...

    I need help with the code below. I am getting an error message I am not sure how to fix import java.util.Scanner; public class DriveTestExams { public static vice main (String[] args);{ Scanner KB = new Scanner (System.in); int IncorrectAns; String[]CA = {"A", "D", "B", "B", "C", "B","A", "B","C", "D","A", "C","D", "B","D", "C","C", "A","D", "A"}; String[]SA = new String [20]; Boolean RightChoice = true; int IncorrectAns = 0; for(int i=o; i <=20; i++){ while (rightchoices); System.out.prinlin ("please enter answer for...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...

  • Identify and correct the error in the following codes, and state what type of error you...

    Identify and correct the error in the following codes, and state what type of error you will get? public class Assignmet2{      public static void main(String []args){        int x=2;        for(int year=1; year>=0; year--)          for (int day=2; day!=3; year++)            {if ( x>=1) System.out.println("Yes");            else System.out.println("No");            x--;} }} int[] grade = new int[20]; for(int counter=0; counter<=grade.length; i++) grade[counter]=20;

  • The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

    The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. import java.util.*; public class DebugEight1 { public static void main(String args[]) { Scanner input = new Scanner(System.in); char userCode; String entry, message; boolean found = false; char[] okayCodes = {'A''C''T''H'}; StringBuffer prompt = new StringBuffer("Enter shipping code for this delivery\nValid codes are: "); for(int x = 0; x <...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are two parts for one code (one question) the two parts branch off, one part has 2 sheets of code, the other has 3 sheets of code, all are small code segments for one question. Pt.1 - 2 sheets of code: public class Computer { private String make; private String type; private String modelNumber; private double cpuSpeed_GHz; private int ramSize_GB; private int hardDriveSize_GB; private...

  • JAVA CODE This program causes an error and crashes. Compile and give it a test run,...

    JAVA CODE This program causes an error and crashes. Compile and give it a test run, note the exception that is thrown. Then do the following to fix the problem 1. Write code to handle this exception 2. Use try, catch and finally blocks. 3. Display, the name of the exception 4. Display a message from the user about what happened. Here is the starting file BadArray.java: public class BadArray { public static void main(String[] args) { // Create an...

  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static...

    Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static void main(String[]args)throws IOException { PhoneBook obj = new PhoneBook(); PhoneContact[]phBook = new PhoneContact[20]; Scanner in = new Scanner(System.in); obj.acceptPhoneContact(phBook,in); PrintWriter pw = new PrintWriter("out.txt"); obj.displayPhoneContacts(phBook,pw); pw.close(); } public void acceptPhoneContact(PhoneContact[]phBook, Scanner k) { //void function that takes in the parameters //phBook array and the scanner so the user can input the information //declaring these variables String fname = ""; String lname = ""; String...

  • Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g...

    Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT