Write a program to input 10 numbers from the user and then display this list of numbers in reverse order. 26. Write a program to input 10 numbers from the user and find their sum and average. After that display all those numbers (entered by the user) which are greater than the average.
Answers
Answer:
reversing 10 numbers-
import java.util.*;
public class Main
{
static int[] reverse(int[] arr){
int n = arr.length;
int[] rev = new int[n];
int j = n;
for(int i = 0; i < n; i++){
rev[j - 1] = arr[i];
j--;
}
return rev;
}
public static void main(String[] args) {
int[] arr = new int[10];
Scanner sc = new Scanner(System.in);
System.out.println("Enter all 10 elements");
for(int i = 0; i < 10; i++){
arr[i] = sc.nextInt();
}
System.out.println("ORIGINAL");
for(int i = 0; i < 10; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("REVERSED");
int[] rev = reverse(arr);
for(int i = 0; i < arr.length; i++){
System.out.print(rev[i] + " ");
}
}
}
2)
import java.util.*;
public class Main
{
public static void main(String[] args) {
int[] arr = new int[10];
int total = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter all 10 elements");
for(int i = 0; i < 10; i++){
arr[i] = sc.nextInt();
total = total + arr[i];
}
double average = total/arr.length;
System.out.println("The average is: " + average);
System.out.println("The numbers greater than the average-");
for(int i = 0; i < arr.length; i++){
if(arr[i] > average){
System.out.print(arr[i] + " ");
}
}
}
}
Explanation: