所以我有以下数组:
String [] randomList = new String [16];
randomList[0]="Dog";
randomList[1]="Dog";
randomList[2]="Cat";
randomList[3]="Cat";
randomList[4]="Mouse";
randomList[5]="Mouse";
randomList[6]="Car";
randomList[7]="Car";
randomList[8]="Phone";
randomList[9]="Phone";
randomList[10]="Game";
randomList[11]="Game";
randomList[12]="Computer";
randomList[13]="Computer";
randomList[14]="Toy";
randomList[15]="Toy";
Run Code Online (Sandbox Code Playgroud)
我想只改变这个数组的前9个元素.我使用了以下代码,但它将整个数组洗牌.
Collections.shuffle(Arrays.asList(randomList));
Run Code Online (Sandbox Code Playgroud)
我怎么会只改变阵列的一部分而不是整个东西呢?我正在制作一个非常简单的程序,所以我想继续使用Collections类,但欢迎所有解决方案.谢谢
我在java中创建一个简单的登录程序.这是我到目前为止的代码.
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
public class PasswordProgram {
public static String user;
public String password;
public static boolean part1Finish = false;
public File file = new File("D:/file.txt");
public FileWriter UsernameWrite;
public char[] user1;
public void part1() {
System.out.println("Please create an account: ");
Scanner input = new Scanner(System. in );
System.out.println("Type in a username: ");
String user = input.next();
System.out.println("Type in a Password: ");
String password = input.next();
try {
UsernameWrite = new FileWriter(file);
UsernameWrite.write(user);
UsernameWrite.write(password);
System.out.println(user);
UsernameWrite.close(); …Run Code Online (Sandbox Code Playgroud)