Results 1 to 4 of 4
- 02-28-2012, 02:46 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
the code doesn't.i dont know why..plz help me.thanks in advance.
import java.util.HashSet;
import java.util.Random;
/**
*
* @author Acer customer
*/
class rangen {
public int[][] ran(int[][] h) {
Random randNumGenerator = new Random();
int[][] x= new int[3][3];
int f=h.length;
HashSet<Integer> e=new HashSet<Integer>();
for (int i=0; i<3; i++)
{
for (int j = 0; j < 3; j++) {
int a= (randNumGenerator.nextInt(9)+1);
h[i][j]=a;
e.add(h[i][j]);
while(e.size()!=f)
{
x[i][j]=h[i][j];
}
}
}
//System.out.println(x);
return x;
}
public static void main(String[] args) {
// TODO code application logic here
int[][] q=new int[3][3];
int[][] x=new int[3][3];
rangen dok=new rangen();
x=dok.ran(q);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.println(x);
}}
}
}
- 02-28-2012, 03:09 PM #2
Re: the code doesn't.i dont know why..plz help me.thanks in advance.
It's not clear what your code should do, please explain.
Anyway, the while-loop never ends.
- 02-28-2012, 03:13 PM #3
Member
- Join Date
- Feb 2012
- Location
- Delhi, India
- Posts
- 5
- Rep Power
- 0
Re: the code doesn't.i dont know why..plz help me.thanks in advance.
its not working because it is entering an infinite while loop due to the condition in statement while (e.size()!=f) becoz on very first go, e.size=1 and f=3. So control enter looop, stuck there foreverrrrrrrrrrrrrrrrrrr....
Remove this while loop, you will get an array returned of 3*3 size with all random numbers..
Unable to understand the purpose of this additional while loop in your code while (e.size()!=f) { .... } ?
- 03-01-2012, 03:17 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
My code doesn't work! Pane.showOptionDialog()
By 0070071 in forum AWT / SwingReplies: 5Last Post: 01-18-2012, 05:56 AM -
how to convert this pseudocode to java code i dont know
By spinter in forum New To JavaReplies: 1Last Post: 11-21-2011, 07:46 PM -
code wont enter into loop. thanks in advance for your help
By farahm in forum Advanced JavaReplies: 7Last Post: 11-22-2010, 02:38 PM -
This code doesn't work. Why? thanks.
By seanzhang in forum New To JavaReplies: 10Last Post: 07-09-2010, 05:53 AM -
Why doesn't this code accept my code?
By PeterFeng in forum New To JavaReplies: 5Last Post: 02-03-2009, 01:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks