Day 5 - 19 August, 2024
Program 16: WAP to store five numbers in an array and print numbers
import java.util.*;
class P1 {
public static void main(String[] args) {
int[] arr = new int[5];
int i, j;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Five Numbers : ");
for (i = 0; i < 5; i++) {
arr[i] = sc.nextInt();
}
System.out.print("Here is the array : ");
for (i = 0; i < 5; i++) {
System.out.print(arr[i] + " ");
}
}
}
Copy Code
Program 17: WAP to find sum and average of 10 numbers using array
import java.util.*;
class P2 {
public static void main(String[] args) {
int[] arr = new int[10];
int i, sum = 0;
double avg;
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 Numbers : ");
for (i = 0; i < 10; i++) {
arr[i] = sc.nextInt();
sum += arr[i];
}
avg = (float) sum / 10;
System.out.print("Sum of 10 Numbers is " + sum + " and average is " + avg);
}
}
Copy Code
Program 18: WAP to store five numbers in list and display numbers in sorted order
import java.util.*;
class P3 {
public static void main(String[] args) {
int arr[] = new int[5];
int i;
System.out.println("Enter 5 Numbers : ");
for (i = 0; i < 5; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
System.out.print("Here is the sorted array : ");
for (i = 0; i < 5; i++) {
System.out.print(arr[i] + " ");
}
}
}
Copy Code