-
Java Help
ok, here's my code:
All i'm trying to do is to generate a certain amount of random numbers (0-100) then pass them to the class and all the class has to do is to return that value back to the client, but when I run it,it displays something different, thanks in advance
client code:
import java.util.*;
import java.util.Scanner;
public class ch10Ex11SortedArray
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
SelectionSort num;
Random r = new Random();
int values;
String list = "";
System.out.println("Enter the number of values: ");
values = input.nextInt();
int[] myNums = new int [values];
for (int tryIndex = 0 ; tryIndex < values ; tryIndex++)
{
myNums[tryIndex]= r.nextInt(100);
// list += myNums[tryIndex] + " ";
}
num = new SelectionSort(myNums);
System.out.println(num.display());
}
}
class:
public class SelectionSort
{
int[] originalArray;
public SelectionSort(int[] list)
{
originalArray = list;
}
public int[] display()
{
return(originalArray);
}
}
-
Array elements
You can't print an array. You have to print the elements of the array using a loop... for example a "for" loop.
Luck,
CJSL
-
CJSL suggest to you something like this.
Code:
for(int i = 0; i < num.display().length; i++) {
System.out.println(num.display()[i]);
}
Better to read bit about return values from a method.