Posted by : Unknown Thursday, 18 June 2015


import java.util.Scanner;
public class ReverseInputNumbers 
{
   public static void main(String[] args) 
   {
   Scanner input = new Scanner( System.in );
     int[] numbers;
     int count,num;       
     numbers = new int[100];  
     count = 0;               
     System.out.println("Enter up to 100 positive integers (or) enter 0 to end.");
     while (true) 
     {  
        System.out.print("? ");
        num = input.nextInt();
        if (num <= 0) 
        {           
           break;
        }
        numbers[count] = num; 
        count++; 
     }   
     System.out.println("\nYour numbers in reverse order are:\n");    
     for (int i = count - 1; i >= 0; i--) 
     {
         System.out.println( numbers[i] );
     }    
   }

Output:

Enter up to 100 positive integers (or) enter 0 to end. 
? 54
? 45 
? 451 
? 21 
? 32 
? 65465 
? 9779 
? 0

Your numbers in reverse order are:

9779 
65465 
32 
21
451 
45 
54

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

Blog Archive

- Copyright © Learning Java Program - Powered by Blogger -