Posted by : Unknown
Thursday, 18 June 2015
import java.util.Scanner;
public class ReverseInputNumbers
public class ReverseInputNumbers
{
public static void main(String[] args)
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)
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)
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--)
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] );
}
}
}
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