Wednesday, 26 January 2022

A) Write a java program to accept ‘n’ integers from the user & store them in an ArrayList collection. Display the elements of ArrayList collection in reverse order.

 SLIP 13 Q 1

SAVE CODE AS             "arrayList.java"



import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class arrayList {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        System.out.print("enter limit of array : ");
        int num=sc.nextInt();
        ArrayList<String> alist=new ArrayList<>(num);

       
        for(int i=0;i<num;i++){
            System.out.println("Enter "+i+" Element of ArrayList :");
            String elmt=sc.next();
            alist.add(elmt);
        }
        sc.close();
        System.out.println("Orignal list :"+alist);
        Collections.reverse(alist);
        System.out.println("Reverse of a ArrayList is :"+alist);
    }
}

OUTPUT:




1 comment:

  1. Write a java program that asks the user name, and then greets the user by name. Before outputting the user's name, convert it to upper case letters. For example, if the user's name is Raj, then the program should respond "Hello, RAJ, nice to meet you!".

    ReplyDelete

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...