Here you can find the source of swapElements(int length, int maxValue)
public static void swapElements(int length, int maxValue)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { public static void swapElements(int length, int maxValue) { int[] randomArray = new int[length]; for (int i = 0; i < randomArray.length; i++) { randomArray[i] = (int) (Math.random() * maxValue); System.out.print(randomArray[i]); }/*from w ww .j a v a 2 s . com*/ Scanner scan = new Scanner(System.in); System.out.println("\nEnter two indexes from the array above: "); int index1 = scan.nextInt(); int index2 = scan.nextInt(); int num = randomArray[index1]; randomArray[index1] = randomArray[index2]; randomArray[index2] = num; for (int i = 0; i < randomArray.length; i++) { System.out.print(randomArray[i]); } } }