What is an off-by-one error give an example for it from


Question 1: What is an "off-by-one error"? Give an example for it from your experience.

Question 2: What will the output of the following statements?

ArrayList names = new ArrayList();
names.add("Annie");
names.add("Bob");
names.add("Charles");
for (int i = 0; i < 3; i++)
{
String extra = names.get(i);
names.add (extra);
}
System.out.print (names);

Question 3: Declare an array of 10 integers and initialize its elements to the following values: -10; -8; -6; -4; -2; 0; 2; 4; 6;8;10

Question 4: What are nested loops? Give an example of nested loop?

Question 5: What is an infinite loop? Write a for statement to demonstrate it.

Question 6: Rewrite the following loops without using the "for each" (enhanced for loop) construct. Here, values have the type double.
(a) for (double element : values) sum = sum + element;
(b) for (double element : values) if (element == target) return true;

Question 7: Write a Java program that asks the user to input the scores of 10 students. The scores entered must be stored in an array.The program must determine:
(a) The lowest score
(b) The highest score
(c) The average score.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: What is an off-by-one error give an example for it from
Reference No:- TGS0981272

Expected delivery within 24 Hours