Write a for loop to initialize the objects in the ArrayList created in question number 2 above to -1. import java.util.*; public class test {     public static void main(String[] args)     {         int n = 25;         ArrayList list = new ArrayList(n);         for(int i = 0;i

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

Write a for loop to initialize the objects in the ArrayList created in question number 2 above to -1.

import java.util.*;

public class test {
    public static void main(String[] args)
    {
        int n = 25;
        ArrayList<Integer> list = new ArrayList<Integer>(n);
        for(int i = 0;i<n;i++){
            list.add(-1);
        }
        for(int i = 0;i<n;i++){
            System.out.print(list.get(i) + " ");
        }
    }
}
 
Write Java statements to add the integers 1001, 1100, and 1110 to the resulting ArrayList .

 
 
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning