1.
a. Write the Java code to fill a Java array of ints of size 100 with the value -1.
b. Write the Java code to create an ArrayList of Strings, and add the Strings "Just", "Do", "It!" to it.
//TestCodeA.java public class TestCodeA { public static void main(String[] args) { int arr[] = new int[100]; for(int i = 0;i<arr.length;i++){ arr[i] = -1; } for(int i = 0;i<arr.length;i++){ System.out.print(arr[i]+" "); } } }
////////////////////////////////////////////////////////////////////
//TestCodeB.java import java.util.ArrayList; public class TestCodeB { public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("Just"); list.add("Do"); list.add("It!"); for(int i = 0;i<list.size();i++){ System.out.println(list.get(i)); } } }
Get Answers For Free
Most questions answered within 1 hours.