Java 将从程序接收的输入从int更改为string初学者

Java 将从程序接收的输入从int更改为string初学者,java,string,Java,String,我写了一个模拟评分测验的程序,但是我想把我收到的输入从int改为string,这样我就可以输入a,b,c,d作为测验的答案。我该怎么做 import java.util.Scanner; public class Quizzes1 { public static void main(String[] args) { int Questions; int answers; int Quizzes; int numOf

我写了一个模拟评分测验的程序,但是我想把我收到的输入从int改为string,这样我就可以输入a,b,c,d作为测验的答案。我该怎么做

import java.util.Scanner;
public class Quizzes1
{
    public static void main(String[] args)
    {

        int Questions;
        int answers;
        int Quizzes;
        int numOfQs = 0;
        String phrase= "";
        Scanner scan = new Scanner(System.in);

        System.out.println("How many questions are in the quizz?");
        Questions = scan.nextInt();

        char[] key = new char[numOfQs];

        int[] canswers = new int[Questions];
        for (int i=0; i<canswers.length; i++)
     {
  System.out.println("Please give the correct answers " + (i+1) + ": ");
  canswers[i] = scan.nextInt();
     }

        while (!phrase.equals("n"))
        {

            double Correct = 0;
            double Incorrect = 0;
            for (int i=0; i<canswers.length; i++)
            {
            System.out.println("What are the answers that the students put");
            answers = scan.nextInt();
            if (answers == canswers[i])
                Correct++;
            else
                Incorrect++;
            }

            System.out.println("There are " +Correct + " correct answers and " +Incorrect
                +" incorrect answers");
            double Percent = ((Correct / (Correct + Incorrect)) * 100);
            System.out.println("The percentage correct is " +Percent +"%");
            phrase = scan.nextLine();
            System.out.println("Would you like to grade another quiz y/n");
            phrase = scan.nextLine();
        }
    }
}
import java.util.Scanner;
公开课测验1
{
公共静态void main(字符串[]args)
{
智力问题;
int答案;
智力测验;
int numOfQs=0;
字符串短语=”;
扫描仪扫描=新扫描仪(System.in);
System.out.println(“测验中有多少问题?”);
问题=scan.nextInt();
char[]key=新字符[numofq];
int[]canswers=新int[问题];

对于(inti=0;i因为a、b、c和d是单字母,为什么不读字符而不是int或甚至字符串呢

试试看

scanner.nextLine().charAt(0);
使用字符,您仍然可以使用代码的这一部分:

if (answers == canswers[i])
    Correct++;
else
    Incorrect++;
}
这与dasblinkenligh的答案非常相似