Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Help with array

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with array

    Hello ,

    basically i want to write a program to compare 2 answer like the first line is the answer key and all the other lines are the students Id , and answer
    like so :

    TFTFTFTFTFTFTFTFTFTF
    6185 TFTFTFTFTFTF FTFT TF
    64551 TFFTFTTTTTTFFTFTTTTTF

    I know how to put the answer key in a array but do not know how to compare it the all of the other students response also a right answer is +2 , wrong -1 , and blank 0 .

    I know how to write the program but do not know how to to compare I thought about using a if else statement then I realize it was a bad idea , the answer key might change and the result will not be accurate ; and would like to use a array , that what I had .

    if (studentsAnswers[1].charAt(0) == 'F' ){
          counter0 = counter0 + 1;
       }else{
     
     
       if (studentAnswers[1].charAt(1) == 'T'){
          counter1++;
       }else{
            }
     
     
       if (studentsAnswers[1].charAt(2) == FT'){
          counter2++;
       }else{
            }

    I really need some help here guys If someone can help me please do .

    Thanks a lot


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Help with array

    You will need 2 loops. One to loop through students and one to loop through (and compare) the answers.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with array

    Junky ,
    can you please show me how to do it , I am a beginner and don't want to messed up
    Thanks

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Help with array

    Do you know how to write a loop?
    Do you know how to access an element of an array?
    Do you know how to write if statements?
    Do you know how to declare variables?
    Do you know how to increment/change the value of variables?

    Then you know how to do this. Make an attempt and if you get stuck post your code and ask a specific question. Include error messages if you get them.
    Improving the world one idiot at a time!

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Help with array

    Additional to Junky's answer.
    1. Why don't you read String? Will ease your problem.
    2. Well, if you are restricted to use char array, Junky's post is useful to lead you to the solution.

  6. #6
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with array

    Thanks for your response I decided to redo everything from the beginning and I am pretty much stuck there :

    int[] studentID = new int[maxStudent];
    	char [] Answer = new char [19];
     
    	Scanner inFile = new Scanner (new FileReader("C:\\students.txt"));
    	PrintWriter outfile = new PrintWriter("C:\\studentsout.txt");
     
    int noOfStudents = 0;
    	while(inFile.hasNext() && noOfStudents <250){
    	studentID[noOfStudents] = inFile.nextInt(); 
    	Answer[noOfStudents]=inFile.next().charAt(6);
    	noOfStudents++;

    What I need to do next ? I really don't know I have been working on it since yesterday and could not get anything done.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Help with array

    @jeremy: Atleast i couldn't understand what do you need to do? Or what you want to do?
    Well, i will suggest you reading this!!!

Similar Threads

  1. Replies: 4
    Last Post: November 14th, 2011, 10:00 PM
  2. Doubling The Array Size And Randomizing Array Return
    By Pingu00 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 27th, 2011, 10:50 AM
  3. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  4. Replies: 2
    Last Post: May 6th, 2011, 05:19 PM
  5. 2d (4x4) array insdie a 1d array. (Block cipher)
    By fortune2k in forum Collections and Generics
    Replies: 13
    Last Post: November 23rd, 2010, 05:29 PM