这是一个记忆实验,在屏幕上最多闪烁 3 个数字,然后消失几秒钟,然后要求用户重播数字/秒。我正在尝试使用数组来计算用户答案的准确性。所以我试图使用带有随机生成器方法的二维数组来判断数字在哪里。这可能效率很低,但我正在尽力而为。这是我到目前为止...
import java.util.*;
public class Pitt3
{
static int pause = 4;
static int Screen_Size = 100;
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
//USED TO CALC. USER'S ACCURACY
int accuracy = 99;
for (int x = 0; x<2; x++)
{
//CREATES ARRAYS TO GENERATE DIGITS
int[] array1 = new int[generateDigits(1)];
int[] array2 = new int[generateDigits(1)];
int[] array3 = new int[generateDigits(1)];
//PRINTS OUT #'S + PAUSES
System.out.println("Here are your numbers: ");
System.out.println(generateDigits(1));
System.out.println(generateDigits(1));
System.out.println(generateDigits(1)); pause(4);
//SPACES OUT THE QUESTION FROM ANSWER
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//PRINTS OUT #'S + PAUSES
System.out.println("What is the first number? ");
int ANSWER1a = keyboard.nextInt();
System.out.println("What is the second number? ");
int ANSWER1b = keyboard.nextInt();
System.out.println("What is the third number? ");
int ANSWER1c = keyboard.nextInt();
if (ANSWER1a != array1[0] || ANSWER1b != array2[0] || ANSWER1c != array3[0])
{
accuracy = (accuracy - 33);
}
if (ANSWER1a == array1[0] || ANSWER1b == array2[0] || ANSWER1c == array3[0])
{
accuracy = accuracy;
}
System.out.println("Your accuracy was " + accuracy + "%");
}
}
/**
*GENERATES A RANDOM #
*/
public static int generateDigits(int maxDigits)
{
Random generator = new Random();
int numberDigits = generator.nextInt(maxDigits) + 1;
int result = 0;
for(int n = 0; n < numberDigits; n++)
{
result = result + generator.nextInt(10);
}
return result;
}
/**
*SETS COMP. TO SLEEP FOR SPECIFIED SECONDS
*/
public static int pause (int seconds)
{
try
{
Thread.sleep(seconds * 1000);
}
catch (InterruptedException e){}
return pause;
}
}