Java Scanner Usage swapElements(int length, int maxValue)

Here you can find the source of swapElements(int length, int maxValue)

Description

swap Elements

License

Open Source License

Declaration

public static void swapElements(int length, int maxValue) 

Method Source Code

//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]);
        }

    }
}

Related

  1. selectProject(List projectList)
  2. splitLines(String string)
  3. splitToDouble(String input)
  4. stringToArray(String str)
  5. stringToDoubleList(String s)
  6. termInput()
  7. Tokenize(String s, String s2, String s3)
  8. toNumeric(String ip)
  9. toWords(String content)