My program asks the user for their name and age. The username is their name and age plus a random character at the end of it. I want to store that username into a new text file but whenever I run the code it only writes one username at a time it doesn't include the one that I added before. Here is my code Please help me I am new.
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
public class Userfile {
private static String name;
private static Scanner scanage;
private static Scanner scan;
public static void main(String[] args) throws IOException {
Random r = new Random();
int age;
String username;
char randomc = 2;
System.out.println("Please enter your name");
scan = new Scanner(System.in);
name = scan.nextLine();
System.out.println("Please enter your age");
scanage = new Scanner(System.in);
age = scanage.nextInt();
username = name.toLowerCase()+age;
String alphabet = "xy!&69£zHDErnABCabcFfGghIiJjKkLlMmNPp";
for (int i = 0; i < 1; i++) {
randomc = alphabet.charAt(r.nextInt(alphabet.length()));
String userId = username + randomc;
System.out.println("Your Username is " +userId);
}
FileWriter userid = new FileWriter("file path");
String userId = username + randomc;
userid.write("\n" + "Username: " + userId);
userid.close();
}
}