Professional Documents
Culture Documents
Lab CSC248
Lab CSC248
1. Compile and run the program in below. Determine the output program
Answer:
Answer:
import java.util.*;
import java.util.ArrayList;
public class Q2 {
public static void main (String[]args){
Answer:
import java.util.*;
public class Lab2_Q3{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
numAL.add(10.5); numAL.add(20.3);
numAL.add(15.5);
System.out.println("Contents of numAL: " + numAL);
//Asks user to enter another 3 floating point numbers.
//Display the list.
System.out.println("Please enter another 3 floating
points numbers:");
double num ;
for(int i=0; i<3; i++)
{ num= scan.nextDouble();
numAL.add(num); //2. add into list
}
System.out.println("Contents of numAL: " + numAL);
//3. Calculate and display the summation of elements in
an index position 0, 2, 4.
double sum = numAL.get(0) + numAL.get(2) + numAL.get(4);
//retrieve 3 elements
Output: