skip to Main Content

JAVA: REVERSE THE NUMBERS ENTERED

JAVA: REVERSE THE NUMBERS ENTERED

JAVA: REVERSE THE NUMBERS ENTERED

Java: Reverse the numbers entered)

package chapter7_7_2; import java.util.Scanner; /** * * @author Siavash Bakhshi */ public class Chapter7_7_2 { /** * @param args the command line arguments */ public static void main(String[] args) { int[] myList = new int[10]; // Create a Scanner java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter " + myList.length + " values: "); for(int i = 0; i < myList.length; i++) { myList[i] = input.nextInt(); } System.out.println("Reverse the numbers entered: "); for(int i = myList.length-1; i >= 0; i--) { System.out.print(myList[i] + ", "); } System.out.println("n"); } }