In: Computer Science
Please find your solution below and if doubt comment and do upvote.
public class ArrayTen {
private String myData[] = new String[10];
public void set(int index, String value) {
try{
myData[index] = value;
}
catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
}
public String get(int index) {
String data="";
try{
data= myData[index];
}
catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
return data;
}
public static void main(String[] args) {
ArrayTen a = new ArrayTen();
a.set(10, "hello world");
System.out.println (a.get(10));
}
}