Question

1. a. Write the Java code to fill a Java array of ints of size 100...

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.

Homework Answers

Answer #1
//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));
        }
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in Java that creates an array of doubles. The array must have size...
Write a program in Java that creates an array of doubles. The array must have size 1000. Fill this array with random numbers between 0 and 1. Then compute and print the total value of all the elements of the array, the mean, the minimum, and the maximum. Filling the array with random numbers must be done by a method that you define and implement. Computing and printing the statistics must be done by another method, which again you must...
Write a c++ function which takes two parameters: an array of ints and an int size...
Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void printSome(const int array[], int size);
Java Write a method that uses an ArrayList and its contains method to take an input...
Java Write a method that uses an ArrayList and its contains method to take an input array of strings return a new array, free of any duplicate strings.
Write Java code that creates an array of primitive integers named odds and stores all odd...
Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
Java Lab Assignment Write a method named findMax. The method will take an array of doubles...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) . method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for...
JAVA CODE Write a program which has a 3D array and prints the integers from the...
JAVA CODE Write a program which has a 3D array and prints the integers from the array. Then then convert the output into a file using filewriter
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering...
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering “Scanner in = new Scanner (System.in);”, input a value into element 5 of one-dimensional double array nums. c) Initialize each of the four elements of the one-dimensional integer array test to 7. d) Declare and create an array called table as a float array that has four rows and three columns. e) Considering the following ArrayList declaration, insert “test” at the fourth position (index...
Write Java code to create a 2D array that mimics the one below. Do not use...
Write Java code to create a 2D array that mimics the one below. Do not use curly brackets to assign values. Instead, use nested loops and if-else or switch. x o o o x o x o x o o o z o o o x o x o x o o o x
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Write an application in Java which includes an algorithm that takes an array of any size,...
Write an application in Java which includes an algorithm that takes an array of any size, selects the high and low integer from the array of integers with each pass and builds a new array of integers by inserting the high and low selection with each pass. Your output should show the original array of integers and the output of each pass on a new line. Note: You can assume all integers are positive, but your code must work for...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT