我正在编写一个程序,要求我从字母表中生成随机字母并将其分配给其他字母.(这是一个加密程序).问题是,一旦我生成了前几个字母,就会再生成一些字母.
例如,我想让a = c(随机生成的字母)但是现在使用了c,我不希望其他25个字母等于c.所以我不想要b = c我不知道如何去做,因为它似乎很容易,但我无法做到这一点.
这是我的代码.
for (int i = 0; i<26; i++)
{
Random r = new Random();
cipherArray[i] =(char)(cipherText.charAt(r.nextInt(cipherText.length())));
}
return cipherArray;
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助,谢谢.
我正在制作一个Hi-Lo纸牌游戏作为编程任务.我检测用户是想要猜测更高,更低还是更低的代码如下.
DeckOfCards deck = new DeckOfCards();
PlayingCard card = deck.deal();
PlayingCard next = deck.deal();
System.out.println("Welcome to the High Low Card Game.\n" +
"You're current card is: "+card.toPictograph() +
". Will the Next card be higher/lower/equal "+
"to the current card?\nType Quit to exit.");
Scanner inputScanner = new Scanner(System.in);
if(inputScanner.hasNext("higher")){
System.out.println("Congradulations you won");
wins++;
}
else if (inputScanner.hasNext("lower"))
{
System.out.println("You suck");
}
else if (inputScanner.hasNext("equal"))
{
System.out.println("You suck");
}
Run Code Online (Sandbox Code Playgroud)
如果我键入'higher','lower'或'equal'(没有''),程序什么都不做.有任何想法吗?谢谢