mardi 24 mars 2015

Command line arguments application

I am having some difficulties with a beginners application. I am supposed to create an application that accepts as command line arguments a sentence and prints out the words that makes up the sentence in random order. The application should print out until the original sentence is reached. For some reason the application I made is not working. What am I doing wrong?



package assignment_7;

import java.util.Arrays;
import java.util.Random;

public class Assignment_7 {
public static void main(String[] args) {


Random shuffle = new Random();

String[] compareString = new String[]{"I", "am", "human"};

do
{
for(int i = 0; i < args.length; i++)
{
int randomPos = shuffle.nextInt(args.length);
String temporary = args[i];
args[i] = args[randomPos];
args[randomPos] = temporary;
System.out.print(args[i] + " ");
}
System.out.print("\n");
}
while (!Arrays.equals(args, compareString));
}


}





Aucun commentaire:

Enregistrer un commentaire