Computer Applications
Write a program that reads ten integers and displays them in the reverse order in which they were read.
Answer
import java.util.Scanner;
public class KboatSDAReverse
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[10];
System.out.println("Enter 10 integers:");
for (int i = 0; i < 10; i++) {
arr[i] = in.nextInt();
}
System.out.println("Integers in reverse order:");
for (int i = 9; i >= 0; i--) {
System.out.print(arr[i] + " ");
}
}
}
Output
Related Questions
Write a program to accept the year of graduation from school as an integer value from the user. Using the binary search technique on the sorted array of integers given below, output the message "Record exists" if the value input is located in the array. If not, output the message "Record does not exist".
Sample Input:n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9] 1982 1987 1993 1996 1999 2003 2006 2007 2009 2010 Write a program that reads a long number, counts and displays the occurrences of each digit in it.
Write Java statements for the following:
i. Create an array to hold 15 double values.
ii. Assign the value 10.5 to the last element in the array.
iii. Display the sum of the first and the last element.
iv. Write a loop that computes the sum of all elements in the array.
Write a program to input 10 integer elements in an array and sort them in descending order using bubble sort technique.