I have reformatted and slightly amended your code ...
Code:
import java.util.Random;
import java.util.Scanner;
import java.lang.String;
public class UserID
{
public static void main(String args[]) {
Scanner login = new Scanner(System.in);
System.out.println("Enter your full Name: ");
String Fullname = login.nextLine();
Fullname = (Fullname).toUpperCase();
String[] splits = Fullname.split("\\s+");
for(String Fname: splits) {
char Finame = Fname.charAt(0);
char endname = Finame;
Random r = new Random();
String userid = "";
for (int i = 10; i < 90; ++i) {
int rand = r.nextInt(1) + 90;
userid = String.valueOf(rand);
}
String User = (endname + userid);
System.out.println(User);
}
}
}
It should become clear from the indentation that your first "for" loop (the one which iterates round the "splits" array) also generates and appends the "random" number. Changing the final print to a println makes this more obvious:
Code:
Enter your full Name:
John peter smith
J90
P90
S90
So maybe your first for loop should be more like:
Code:
String endname = "";
for(String Fname: splits) {
char Finame = Fname.charAt(0);
endname = endname + Finame;
}
Note that this (above) is not good code - it's a very inefficient way of appending characters to a string, but I don't want to introduce the complexity of using a string buffer to do it the correct way.
Now, looking at the "random number" generator:
Code:
String userid = "";
for (int i = 10; i < 90; ++i) {
int rand = r.nextInt(1) + 90;
userid = String.valueOf(rand);
}
Random.nextInt(1) will always return 0. Javadoc for Random class states : Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive). It is being executed 79 times by the for loop. I suspect what you really want is something like:
Code:
String userid = "";
int rand = r.nextInt(90) + 1;
userid = String.valueOf(rand);
Which will generate a random number between 0 and 89, then add 1 to it giving a random number between 1 and 90.
Then simply concatenate the "endname" and "userid" variables and you're done.
Code:
Enter your full Name:
john peter smith
JPS51