我需要创建一个由三个随机大写字母和三个随机数字组成的字符串,并输出我已经完成的结果。接下来我需要将整个字符串变为小写,输出结果,然后只将第一个字符变为大写并输出结果。我一直在尝试使用substring()
,但它没有编译,我不太确定如何使用substring()
随机生成器。这是我写的,如果我能得到一些帮助,那就太好了。
import java.util.Random;
public class RandomString
{
public static void main(String[] args)
{ Random generator = new Random();
int randomNumber = generator.nextInt(2);
char randomChar = (char)('A');
System.out.print("A random string is " + randomChar);
randomNumber = generator.nextInt(26);
randomChar = (char)('A' + randomNumber);
System.out.print(randomChar);
randomNumber = generator.nextInt(26);
randomChar = (char)('A' + randomNumber);
System.out.print(randomChar);
randomNumber = generator.nextInt(10);
System.out.print(randomNumber);
randomNumber = generator.nextInt(10);
System.out.print(randomNumber);
randomNumber = generator.nextInt(10);
System.out.println(randomNumber);
}
}