Saturday 20 August 2016

Chapter 7 Exercise 2, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

7.2 (Reverse the numbers entered) Write a program that reads ten integers and dis- plays them in the reverse of the order in which they were read.



import java.util.Scanner;
 
public class ProgrammingEx7_2 {
 
 public static void main(String[] args) {
 
  Scanner input = new Scanner(System.in);
  int[] number = new int[10];
 
  System.out.print("Enter 10 integers:");
 
  for (int i = 0; i < number.length; i++) {
   number[i] = input.nextInt();
  }
 
  for (int i = number.length - 1; i >= 0; i--) {
   System.out.print(number[i] + " ");
  }
 
 }
 
}

No comments :

Post a Comment