Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There are some errors with the compulation of the java code below, please correct ut and send the source code with the output. Thank You
There are some errors with the compulation of the java code below, please correct ut and send the source code with the output. Thank You
import java.util.Arrays;
public class SimpleArrays{
String[] data = new String[4];
public SimpleArrays() {
Arrays.fill(data,"Hello, world");
}
public SimpleArrays (String val) {
Arrays.fill (data, val);
}
public String arrayConcat (int index) {
String output = "";
if (index >= data.length)
throw new ArrayIndexOutOfBoundsException();
for (int i = index; i
output += data[i] + "#";
}
output += data[data.length-1];
return output;
}
public String arrayConcat() {
int index = 0;
String output = "";
if (index >= data.length)
throw new ArrayIndexOutOfBoundsException();
for (int i = index; i
output += data[i] + "#";
}
output += data[data.length-l];
return output;
public String arrayCrop(int start, int end) {
if (start > end) {
int temp = start;
start = end;
end = temp;
if (start = data.length)
return "Fail";
if (start == end)
return "Match";
String output="";
for (int i = start; i
Compilation failed due to following error(s). Main.java:17: error: expected output += data[data. Length-1); Main.java:18: error: illegal start of type return output; Main.java:18: error: expected return output; Main.java:20: error: class, interface, or enum expected public String arrayConcat() { Main.java:22: error: class, interface, or enum expected String output = ""; Main.java:23: error: class, interface, or enum expected if (index >= data. length) Main.java:25: error: class, interface, or enum expected for (int i = index; i = data. length) Main.java:37: error: class, interface, or enum expected if (start = end) A Main.java:39: error: class, interface, or enum expected String output=""; A Main.java:40: error: class, interface, or enum expected for (int i = start; i output += data[i]+"#";
}
output += data[end-1];
return output;
}
public static void main(String[] args) {
SimpleArrays myArrayl = new SimpleArrays();
String foundResultl = myArrayl.arrayConcat();
System.out.println(foundResultl);
SimpleArrays myArray2 = new SimpleArrays ();
String foundResult2 = myArray2.arrayConcat(2);
System.out.println(foundResult2);
SimpleArrays myArray3 = new SimpleArrays ("Hi you" );
String foundResult3 = myArray3.arrayConcat();
System.out.println(foundResult3);
SimpleArrays myArray4 = new SimpleArrays ("Hi you" );
String foundResult4 = myArray4.arrayConcat(2);
System.out.println(foundResult4);
SimpleArrays myArray5 = new SimpleArrays ( "Hi you" ) ;
String foundResult5 = myArray5 .arrayCrop(0,2);
System.out.println(foundResult5);
SimpleArrays myArray6 = new SimpleArrays ("Hi you" ) ;
String foundResult6 = myArray6.arrayCrop(3,2);
system.out.println(foundResult6);
SimpleArrays myArray7 = new SimpleArrays ( "Hi you" ) ;
String foundResult7 = myArray7.arrayCrop(0,6);
System.out.println(foundResult7);
SimpleArrays myArray8 = new SimpleArrays ("Hi you" ) ;
String foundResult8 = myArray8. arrayCrop(3,3);
System.out.println (foundResult8);
}
}
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