static Array List Integer Q6t Create and return an Array Lis

static Array List Integer Q6()t Create and return an Array List of the integers 1 through 10 (including 1 and 10) ArrayList

Solution

Method:

static ArrayList Q6() {
       int i=1;
       ArrayList<Integer> list=new ArrayList<Integer>();
       while(i<=11)
       {
           list.add(i);
           i++;
       }
       return list;
   }

}

__________________

Complete Program:

DemoClass.java

import java.util.ArrayList;

public class DemoClass {


   public static void main(String[] args) {
       ArrayList arl=Q6();
for(Object i:arl)
{
   Integer ii=(int)i;
   System.out.println(ii);
}
   }

   private static ArrayList Q6() {
       int i=1;
       ArrayList<Integer> list=new ArrayList<Integer>();
       while(i<=11)
       {
           list.add(i);
           i++;
       }
       return list;
   }

}

_________________

Output:

1
2
3
4
5
6
7
8
9
10
11

__________Thank You

 static Array List Integer Q6()t Create and return an Array List of the integers 1 through 10 (including 1 and 10) ArrayListSolutionMethod: static ArrayList Q6(
 static Array List Integer Q6()t Create and return an Array List of the integers 1 through 10 (including 1 and 10) ArrayListSolutionMethod: static ArrayList Q6(

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site