cristi pela
Posts: 1
Nickname: krissti
Registered: Nov, 2005
|
|
Re: Comparing Arrays
|
Posted: Nov 6, 2005 10:32 AM
|
|
hy! I know that's too late but I think that my solution might help you sometimes:
public static void main(String []arg){ //here are some vectors; Vector vectorQuestions=new Vector(),vectorAnswers=new Vector(); int questions, count, count2, count3, count4,report; int[] xxx, rightAnswers, gradedAnswers; //set up the scanner and get the number of questions on the test-which will be size of all arrays Scanner scan = new Scanner(System.in); System.out.print("How many questions were on the quiz? "); questions = scan.nextInt(); //set all the arrays to size of questions that was just input by user xxx = new int[questions]; rightAnswers = new int[questions]; gradedAnswers = new int[questions]; //read in the array of correct answers(answer key) System.out.print("\nEnter the correct answers for "+questions+" questions. (Answer key)\n"); for(count = 0; count < xxx.length; count++) { rightAnswers[count] = scan.nextInt(); } //read in the array of numbers to be checked against the key System.out.print("\nEnter the answers for the quiz to be graded\n"); for(count2 = 0; count2 < xxx.length; count2++) { gradedAnswers[count2] = scan.nextInt(); } //simple formatted printing as shown on assignment sheet System.out.println("\n GRADE REPORT "); System.out.println("----------------------"); //print the correct answers as entered System.out.print("Correct Answers: "); for(count3 = 0; count3 < rightAnswers.length; count3++) { System.out.print(" "+rightAnswers[count3]); vectorQuestions.addElement(new Integer(rightAnswers[count3])); } //print the graded answers as entered System.out.print("\nYour Answers: "); for(count4 = 0; count4 < gradedAnswers.length; count4++) { System.out.print(" "+gradedAnswers[count4]); vectorAnswers.addElement(new Integer(gradedAnswers[count4])); } //AND HERE IS THE FUNNY PART:------------------------------ System.out.print("\nQuestion missed :"); for(report=0;report<xxx.length;report++){ if(vectorQuestions.elementAt(report).equals(vectorAnswers.elementAt(report))){ System.out.print(" -"); }else System.out.print(" *"); } //---------------------------------------------------------------- }
|
|