Results 1 to 3 of 3
Thread: Java Help
- 12-18-2008, 03:23 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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);
}
}
- 12-18-2008, 03:58 AM #2
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-18-2008, 05:12 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
CJSL suggest to you something like this.
Better to read bit about return values from a method.Java Code:for(int i = 0; i < num.display().length; i++) { System.out.println(num.display()[i]); }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks