|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Oct 2009
Messaggi: 239
|
[JAVA] Stringa di numeri random di lunghezza x
Devo creare una stringa di numeri casuali di "x" cifre, ho provato cosi ma il metodo mi restituisce una stringa di numeri e lettere mentre io vorrei solo numeri:
Codice:
public String randomString (int x) {
Random rnd = new Random ();
char[] arr = new char[x];
for (int i=0; i<x; i++) {
int n = rnd.nextInt (9);
arr[i] = (char) n;
}
return arr.toString();
}
|
|
|
|
|
|
#2 | |
|
Member
Iscritto dal: Jul 2005
Messaggi: 291
|
Quote:
Codice:
public String randomString(int x){
Random rand=new Random();
String res="";
for (int i=0;i<x;i++){
res+=String.valueOf(rand.nextInt(9));
}
return res;
}
__________________
CPU: Intel Core 2 Quad Q6600 - Mobo: Asus P5E - RAM:4x2GB DDR2 - sk video: Power Color ATI Radeon HD3870 - HD:Western Digital 750GB |
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Oct 2009
Messaggi: 239
|
e anche bene! grazie mille! devo dire che sto approfittando troppo di questo forum, ma sono troppo pigro!
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:19.




















