Question
This is java code. public class Lamb { String[] array = { Mary, had, a, little, lamb, null , null , null , null ,
This is java code.
public class Lamb
{
String[] array = { "Mary", "had", "a", "little", "lamb",
null, null, null, null, null };
int size = 5;
void insert (String word, int index) {
}
/** Print the words in array from 0 to size-1. */
void print () {
for (int i = 0; i < size; i++)
System.out.print(array[i] + " ");
System.out.println();
}
public static void main (String[] args) {
Lamb lamb = new Lamb();
lamb.print();
lamb.insert("very", 3);
lamb.print();
lamb.insert("only", 1);
lamb.print();
lamb.insert("Doctor", 0);
lamb.print();
lamb.insert("chop", 8);
lamb.print();
lamb.insert("eaten", 4);
lamb.print();
System.out.println("Final sentence should be:");
System.out.println("Doctor Mary only had eaten a very little lamb chop");
}
}
The output is:
Mary had a little lamb Mary had a little lamb Mary had a little lamb Mary had a little lamb Mary had a little lamb Mary had a little lamb Final sentence should be: Doctor Mary only had eaten a very little lamb chop
!!!!!!!! Make some changes in the original code ,then your output should be:
Mary had a little lamb Mary had a very little lamb Mary only had a very little lamb Doctor Mary only had a very little lamb Doctor Mary only had a very little lamb chop Doctor Mary only had eaten a very little lamb chop Final sentence should be: Doctor Mary only had eaten a very little lamb chop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started