This discussion is archived
2 Replies Latest reply: May 23, 2013 12:48 PM by aksarben RSS

Help with array/file lab

1009788 Newbie
Currently Being Moderated
Directions for lab: Your twin cousins, Ryan and Dana, have been collecting baseball cards for years. The cards are numbered sequentially from 1 to n. One day, while examining the cards, Ryan dropped them and one of the cards fell through a crack in the floor. Ryan would like to replace the lost card and has sent you a list of the n-1 cards he has recovered. Your job is to determine the lost card number before Dana realizes it’s missing.

Inputs
The first input line will contain the number of cases to process. This will be followed by one line per case that contains the number of baseball cards in the collection (which includes the lost card) followed by the card numbers of the cards that Ryan recovered. The numbers are separated by a space.

Outputs
There will be one line of output per case that gives the lost card number for that case.

My Code:
import java.io.*;
import java.util.*;

public class Stj1 {

     /**
      * @param args
      */
     public static void main(String[] args) throws IOException {
          String input;
          int count=0, count2=0;
          int store=0, temp=0;
          String count1="1";
          FileReader fr = new FileReader("Twins.txt");
          BufferedReader br = new BufferedReader(fr);
          String [] elements =new String[100];
          String [] newelements = new String[100];
          
          while((input=br.readLine())!=null)
          {
               System.out.print(input);
               elements =input.split(" ");
               int b = Integer.parseInt(elements[0],10);
               System.out.println(b);
               String [] def = new String;
               
               for(int i=1; i<elements.length; i++)
               {
                    newelements[count]=elements;
                    count++;
               }
               count1="1";
               for(int k=0; k<def.length; k++)
               {
                    def[k]=count1;
                    int c = Integer.parseInt(count1,10);
                    c++;
                    count1= "" + c;
                    System.out.println(c);
               }
               for(int i=0; i<def.length; i++)
               {
                    for(int j=0; j<def.length-1; j++)
                    {
                         System.out.println(newelements[j] + def[i]);
                         
                         if(def[i].equals(newelements[j]))
                         {
                              count2++;
                              
                         }
                         temp=i;
                    }
                    if(count2==0)
                    {
                         store= temp;
                         System.out.print("xxxxxxxxxxxxxxxxx");
                         
                    }
                    count2=0;
               }
               System.out.println(def[store]);
          }
     }
}
I keep getting errors....help please!

Edited by: EJP on 20/05/2013 11:47: added {noformat}
{noformat} tags: please use them.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points