For full functionality of this site it is necessary to enable JavaScript. Here are the instructions how to enable JavaScript in your web browser.

All for Joomla All for Webmasters
Close

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");
    }
    
}
Java: Reverse the numbers entered) (594 downloads)