Comparing arrays - help!

Hello. I've been trying to solve this problem for hours, and I would be most grateful for any help you can give me.
Basically, I'm trying to compare two arrays of char and tell first how many are the same in the same place (I can do that) and then how many are the same but not in place. However, if there are two of one char in one array, and one of the same char in the other, I only want to count it once.
The problem is, I can't figure out how to do this. I'm using for loops and then setting the char to 0 if it finds a match. This doesn't work. I tried using a series of if statements but I got weird run time acceptions sometimes, and when I put in more if statements to combat that, 1.) it got too confusing and 2.) still only worked half the time. So I'm back to the for loops.
Here's what I have:
for (int j = 0; j<guess1.length; j++){
for(int k = 0; k<code1.length; k++){
if(code1[k]== guess1[j]){
code1[k]=0;
guess1[j] = 0;
almost = almost + 1;
So if the code is BBYG and the guess is BWWY, it should return 1 correct and one almost. It will return the one correct, but then return 3 for the almost. It looks at the B in guess which already returned the correct and find it an almost against both B's. When it should have been set to 0 in the correct for loop.
Sorry, I ramble a bit. Hope you can help!
Thanks.

You're gonna love this.
Unless you have some annoying and patently backward lecturer who wants you to everything the hard way then get ye nose into:
1. the Collections framework.
http://java.sun.com/docs/books/tutorial/collections/index.html
2. and the Collections class itself.
http://java.sun.com/javase/6/docs/api/java/util/Collections.html
Hint: a Map can be used to find the distinct items in a list.

Similar Messages

  • Compare arrays

    Hello all, I am new to labview and i am trying to compare two arrays to see if they are equal. What i am trying to do is read cell values from excel and move them into an array. Then i would like to compare that array with a constant array in my labview program. Any help is greatly appreciated.

    Do attention with the "aggregates" function.
    Comparing two arrays, for example 3,2,1,0 and 3,2,1 gives "different"
    When comparing if all values in an array are zero, the dimension must also be right !
    So before comparing the values, I compare the length, causing an error if unequeal.
    In my case, compare if everything is zero, I use the "Array max&min" function. (Max<>0 and Min <>0)
    Message Edited by ST5 on 08-11-2009 05:00 AM

  • Comparing array members

    i cant solve the 2nd part of this prob (found in this forum):
    // Generate lottery numbers (from 1-49)
    // Print number of occurrences of each number
    public class Lotaria {
         public static void main(String[] args) {
              int x = 1;
              int p = 1;
              int s = 1;
              int n = 1;
              int[] loto = new int[49];    // n?s do loto
              // Generating lottery numbers (from 1-49)
              for ( n = 0; n < 49; n++ ) {
                   loto[n] = (int)(Math.random() * 49 + 1);
                   System.out.println(loto[n]);
              for ( p = 0; p < loto.length; p++ ) {
                   for ( s = 0; s < loto.length; s++ ) {
                        if ( loto[p] == loto[s] ) {
                             x++;
                             System.out.println(loto[p]
                                              + " ocorre " + x + " vezes");// prints nonsenses
    }looks like (inside the if) i'm comparing every array element to all the others and then counting each repetition...
    can someone sort me out of this, or at least give me an hint? (pls dont ask for interfaces)

    I did it!
    // Generate lottery numbers (from 1-49)
    // Print number of occurrences of each number
    public class Lotaria {
         public static void main(String[] args) {
              int x = 0;
              int p = 1;
              int s = 1;
              int n = 1;
              int[] loto = new int[49];
              // Generating lottery numbers (from 1-49)
              for ( n = 0; n < 49; n++ ) {
                   loto[n] = (int)(Math.random() * 49 + 1);
                   System.out.println(loto[n]);
              for ( p = 0; p < loto.length; p++ ) {
                   for ( s = 0; s < loto.length; s++ ) {
                        if ( loto[p] == loto[s] ) {
                        x++;
              System.out.println(loto[p] + " ocorre " + x + " vezes");
              x = 0;
    }i think the 3rd loop (my original idea) can be more elegant but right now i cant cope with it
    the secret was in resetting "x"!...
    thanks to both for helping me

  • Loops and Arrays help

    Hi,
    I'm a freshman in college and new to java. I am completely lost and really need help with a current assignment. Here are the instructions given by my teacher...
    Building on provided code:
    Loops and Arrays
    Tracking Sales
    Files Main.java and Sales.java contain a Java application that prompts for and reads in the sales for each of 5 salespeople in a company. Files Main.java and Sales.java can be found here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Main.java
    and here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Sales.java It then prints out the id and amount of sales for each salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:
    1. (1 pts) Compute and print the average sale. (You can compute this directly from the total; no new loop is necessary.)
    2. (2 pts) Find and print the maximum sale. Print both the id of the salesperson with the max sale and the amount of the sale, e.g., "Salesperson 3 had the highest sale with $4500." Note that you don't necessarily need another loop for this; you can get it in the same loop where the values are read and the sum is computed.
    3. (2 pts) Do the same for the minimum sale.
    4. (6 pts) After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the id of each salesperson who exceeded that amount, and the amount of their sales. Also print the total number of salespeople whose sales exceeded the value entered.
    5. (2 pts) The salespeople are objecting to having an id of 0-no one wants that designation. Modify your program so that the ids run from 1-5 instead of 0-4. Do not modify the array-just make the information for salesperson 1 reside in array location 0, and so on.
    6. (8 pts) Instead of always reading in 5 sales amounts, allow the user to provide the number of sales people and then create an array that is just the right size. The program can then proceed as before. You should do this two ways:
    1. at the beginning ask the user (via a prompt) for the number of sales people and then create the new array
    2. you should also allow the user to input this as a program argument (which indicates a new Constructor and hence changes to both Main and Sales). You may want to see some notes.
    7. (4 pts) Create javadocs and an object model for the lab
    You should organize your code so that it is easily readable and provides appropriate methods for appropriate tasks. Generally, variables should have local (method) scope if not needed by multiple methods. If many methods need a variable, it should be an Instance Variable so you do not have to pass it around to methods.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this.
    I'm not asking for someone to do this assignment for me...I'm just hoping there is someone out there patient and kind enough to maybe give me a step by step of what to do or how to get started, because I am completely lost from the beginning of #1 in the instructions.
    Any help would be much appreciated! Thank you!
    Message was edited by:
    Scott_010
    Message was edited by:
    Scott_010

    First ask the person who gave this asignment as to why do you require two classes for this , you can have only the Sales.java class with main method in it . Anyways.
    Let Main.java have a main method which instanciates a public class Sales and calls a method named say readVal() in Sales class.
    In the readVal method of sales class define two arrays i.e ids and sales. Start prompting the user for inputting the id and sales and with user inputting values keep storing it in the respective arrays .. Limit this reading to just 5 i.e only 5 salesPerson.
    Once both the arrays are populated, call another method of Sales class which will be used for all computations and output passing both the arrays.
    In this new method say Compute() , read values from array and keep calculating total,average and whatever you want by adding steps in just this loop. You can do this in readval method too after reading the values but lets keep the calculation part seperate from input.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this. I think this is ur personal stuff , but if you want to use web page , you probably will require to use servlet to read values from the html form passed to the server.

  • Reading from a text file in to an array, help please

    I have the following
    public class date extends Loans{
    public int dd;
    public int mm;
    public int yyyy;
    public String toString() {
    return String.format( "%d,%d,%d", mm, dd, yyyy );
    public class Loans extends Borrowing {
    public String name;
    public String book;
    public date issue;
    public char type;
    public String toString(){
    return String.format( "%s, %s, %s, %s", name, book, issue, type );
    import java.util.Scanner;
    import java.io.*;
    public class Borrowing extends BorrowingList {
    private Loans[] Loaned = new Loans[20];
    if i want to read in from a text file in to that array how do i do it?

    sorry to keep bothering you and thanks loads for your help but now I am getting the following error mesage
    C:\Documents and Settings\MrW\Menu.java:43: cannot find symbol
    symbol : class IOException
    location: class Menu
    }catch(IOException e){
    Note: C:\Documents and Settings\MrW\Borrowing.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    BUILD FAILED (total time: 0 seconds)
    for this line
    }catch(IOException e){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Populating 1D Array, Help with 1 Error

    Hello,
    I have just about finished a program that implements a .txt file containing a few records. The order is an int customerNumber, string firstName, string lastName, and float balance. The snipplet of code posted below is where I believe the problem lies, I just cant figure out where it is. Im not sure if my counter is not working correctly or what. The problem is that I'll input the customer number of the first record and it will output fine, but when I type in any other customer number, it returns null. It is supposed to return null if the customer number is not found in the array. The snipplet of code is posted below and if needed, i will post the entire program. Thanks for any help and feel free to ask questions:
    import java.util.Scanner;
    import java.io.*;
    public class customerList {
         private int count;
         private customerRecord data[];
         public customerList()
         data=new customerRecord[100];
         count=0;
    public void getCustomerList(String fileName) throws IOException
         while(count<100)
         Scanner scan=new Scanner(new File("/Users/kd/Documents/workspace/Assignment1/src/records.txt"));
              int customerNumber=scan.nextInt();
              String firstName=scan.next();
              String lastName=scan.next();
              float balance=scan.nextFloat();
              data[count]=new customerRecord(customerNumber, firstName, lastName, balance);
              count++;
    public customerRecord getCustomer(int customerNumber)
              for(int i=0; i<data.length; i++)
                   if(data.getCustomerNumber()==customerNumber)
                        return data[i];
              return null;

    ahh, i see....stupid mistake. would it still be 'legal' for me to do:
    public void getCustomerList(String fileName) throws IOException
         Scanner scan=new Scanner(new File("/Users/kevindoster/Documents/workspace/Assignment1/src/records.txt"));
         while(count<100)
              int customerNumber=scan.nextInt();
              String firstName=scan.next();
              String lastName=scan.next();
              float balance=scan.nextFloat();
              data[count]=new customerRecord(customerNumber, firstName, lastName, balance);
              count++;
    }or is there a problem with my limitations in the while loop

  • New Builder needs some info K9A Plat. RAID Array help

    This is a new build AMD 64x2 6000+, K9A platinum, Lite On DVD Re Writeable SATA, 2x74Gig WD Raptors in Raid 0, Asus X1950 pro Thermaltake 700 W PSU Crossfire cert.
    BIOS registered my drives, Built array PC Rebooted, Installing Win XP pro Hit F6 install drivers, Format drives, Then before Install  It says that :setup cannot copy the file ahcix86.inf.
    If I skip it, it will install XP but when I try to boot from the hard drive It starts to load XP but crashes to the blue screen of death
    *** Stop: 0x0000007BC ( 0xF78A2524, 0xC0000034, 0x00000000, 0x00000000)
    Has anyone got this error string?
    First RAID array I would very much appreciate any help given.

    Hi!
    Looking at some info on Google and Microsoft site, I cannot find the BC error code, only the error code ending with B. It indicates an error with the boot device. It can be caused by several things.
    Check that you are using the correct device drivers to install Windows
    Also, check the installation CD. It could be that the disk was damaged and that you are missing a crucial file because of that
    You can also try installing Windows again and choose to recover the previous installation.
    If this all does not help, try installing Windows on a single HDD (no raid) to see if that will work.

  • Boolean Array-- Help Plz Urgent

    Can i create and initialize an array of booleans like this ?
    Boolean[51] Position = true;
    Thanks... Plz help

    This works:Boolean[] bools = {
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true)
    };... and, fortunately, so does this:Boolean[] bools = new Boolean[51];
    java.util.Arrays.fill(bools, new Boolean(true));I hope you find this of some help.

  • JTextField array help

    Hey guys,
    I'm working on a java GUI right now and I've come up with a problem, hopefully you guys can help.
    I have a page that contains 50 text fields in 2 columns, so instead of making 50 lines of text field code, I decided to make an array of text fields and a for loop to cycle through each one (setting sizes, colors, editable, etc). Now the problem I'm running into is I will later down the road like to setText in these but it will be very cumbersome to have to call them by the arrayName[index #]. Just so I can better express what I mean heres is how I have to call each text field right now:
    arrayName[0].setText("1");
    arrayName[1].setText("2");
    This is how I'd like to be able to call each field:
    1stTextField.setText("1");
    2ndTextField.setText("2");
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name? If not, is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1];
    Thanks for the help guys.

    50 text fields in 2 columns... why not just use a JTable?
    Is there anyway I can make it so I can make an array of JTextFields and still be able to call an individual text field inside the array by name?Try a HashMap
    is there a way to point to another variable such as making
    1stTextField = arrayName[0] ;
    2ndTextField = arrayName[1]; Yes, exactly as you coded it up

  • Fixed Array help!!!

    i have a fixed array colection....how do i return the highest value in the array....but i need it to return its position in the array
    i have the running loop working to return the highest value in my array but i need it to store the position it is in
    double max = value[0];
            for(int i = 0; i < 12; i++)
                if(value[i] > max)
                    max = value;
    thnx alot for ur help!

    So you're saying this does not work?
    int indexOfMax = 0;
    double max = value[0];
    for(int i = 1; i < value.length; i++)
      if(value[i] > max)
        max = value;
    indexOfMax = i;

  • Urgent array help needed! come get some duke points

    this program keeps track of rentals for a shop. Other methods and classes not shown (like Customer, Transaction classes) are also in this program. Every item (created with a constructor in Item class) can hold an array of up to 20 transactions; part of a Transaction object is a rental total, based on a number of rental days * specific rental price for that item rented (backhoe, edger, etc.) If the user presses "t" for total amount of transactions, the following method is called, which calls the getTotalPrice() in another class called Item. My problem here is that even if I enter in transaction amounts, when I press "t", the program just quits, not producing the report and returning me to the main class. I have been over it with the debugger and I am still lost. Below is some selected code; I hope it is sufficient. Please let me know if I need to put up more
    //main
    String input = JOptionPane.showInputDialog(null, "Enter a rental transaction (x)" +
                                                      "\nAdd a customer (c)" +
                                                      "\nAdd an item (i)" +
                                                      "\nReport on a specific item (r)" +
                                                      "\nReport on total dollar amounts of rentals for all items (t)" +
                                                      "\nReport on total rentals for a specific customer (s)" +
                                                      "\nStrike cancel to exit from the program");
              //big huge while
              while (input != null){
                   if (input.equals("x")){
                        rentalTrans();
                   }//if
                   if (input.equals("c")){
                        addCustomer();
                   }//if
                   if (input.equals("i")){
                        addItem();
                   }//if
                   if (input.equals("r")){
                        specificItemReport();
                   }//if
                   if (input.equals("t")){
                        allItemReport();
                   }//if
                   if (input.equals("s")){
                        customerReport();
                   }//if
                   input = JOptionPane.showInputDialog(null, "Enter a rental transaction (x)" +
                             "\nAdd a customer (c)" +
                             "\nAdd an item (i)" +
                             "\nReport on a specific item (r)" +
                             "\nReport on total dollar amounts of rentals for all items (t)" +
                             "\nReport on total rentals for a specific customer (s)" +
                             "\nStrike cancel to exit from the program");
    //allItemReport()
    public static void allItemReport(){ //menu item t
              Item temp = null;
              for (int index = 0; index < items.length; index++){
                   temp = items[index];
              }//for
              JOptionPane.showMessageDialog(null, "Total rental transactions to date amount to: $" + temp.getTotalPrice());
    //Item Class
    public String getTotalPrice() {
              double total = 0;
              String output = "";
              for (int i = 0; i < trans.length; i++) {
                   if (trans[i] == null) {
                        if (i == 0) {
                             output = "There are currently no transactions.";
                        }// if
                        break;
                   }// if
                   else{
                   total += getPerDayRentalPrice();
                   }//else
              }// for
              output+= total;
              return output;
         }//getTotalPrice

    Don't flag your questions as urgent. It's rude. Also don't think that waving with a couple of worthless Dukes is going to get you better/quicker help.
    The reason I respond to your question is because you have explained your problem well and used code tags.
    Try this:class Main {
        public static void main (String[] args) {
            String message = "Enter a rental transaction (x)\nAdd a customer (c)" +
                "\nAdd an item (i)\nReport on a specific item (r)\nReport on total "+
                "dollar amounts of rentals for all items (t)\nReport on total rentals"+
                " for a specific customer (s)\nStrike cancel to exit from the program";
            String input = JOptionPane.showInputDialog(null, message);
            while(input != null){
                if (input.equals("x")) rentalTrans();
                else if (input.equals("c")) addCustomer();
                else if (input.equals("i")) addItem();
                else if (input.equals("r")) specificItemReport();
                else if (input.equals("t")) allItemReport();
                else if (input.equals("s")) customerReport();
                else System.out.println("Invalid option!");
                input = JOptionPane.showInputDialog(null, message);
            System.out.println("Bye!");
        // the rest of your methods ...
    }

  • Sorting a multi array help

    I am new to programming and have issues writing the proper code to sort an array, I am not looking for anyone to write the entire code for me as it is already done but I cannot get it to sort and print the information by the item name. Here is my array and every code I have tried does not sort the information it only prints in the order of the array.
    Prod[0] = new Product( "Computer", "40-7-1-0", 25, 1250 );
    Prod[1] = new Product( "Video Card", "30-4-18-0", 150, 500);
    Prod[2] = new Product( "Drive", "30-5-20-0", 500, 89);
    When the program shows the data it is supposed to print in order IE
    Computer ....
    Drive ....
    Video Card ...
    I just do not understand how to get the program to sort the information correctly, if anyone can point me towards some information or examples on how to sort the array type it would be greatly appreciated so I can move forward, thanks!!

    try this:
    package com.myCompany;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    public class Product implements Comparable<Product> {
         String      name;
         String      productNumber;
         int      numberInStock;
         /** constructor */
         public Product(String name, String productNumber, int numberInStock){
              this.name=               name;
              this.productNumber=     productNumber;
              this.numberInStock=     numberInStock;
         public String getName(){
              return name;
        public int compareTo(Product n) {
            int lastCmp = name.compareTo(n.name);
            return (lastCmp != 0 ? lastCmp :
                    name.compareTo(n.name));
         public String toString(){
              return name+" "+productNumber+" "+numberInStock;
         /** demonstrates that this class sorts Product by name */
         public static void main(String[] args){
              //lets get an unsorted list of items (name= a,c,b)
              Product product1=new Product("a","1234",5);
              Product product2=new Product("c","1234",7);
              Product product3=new Product("b","1234",3);
              List<Product> products= new ArrayList<Product>();
              products.add(product1);
              products.add(product2);
              products.add(product3);
              Collections.sort(products);
              //this shows products are printed out by name sorted (name= a,b,c)
              for(Product product :  products){
                   System.out.println(product.toString());
    }

  • Printing array help please!

    Hi, I have a problem with printing arrays in a certain order. Let me descbribe it, by the way I'm using Java version 1.3 if that helps.
    ok, what I need to do is print out on a single line all the strings found on the command line that end in .java and then I need to print out all the strings found on the command line that end in .class. So say I type on the command line a.java b.class c.java d.class. Then it would print out a.java c.java b.class d.class.
    any help would be appreciated!

    here it goes the complete code:
    * running example: java a.class b.java c.class d.class h.java
    public class Nickal01
         static public void main(String[] args)
              String classes = "";
              for(int i=0; i<args.length; i++)
                   if(args.endsWith(".class"))
                        classes += args[i] + " ";
                   else
                        System.out.print(args[i]+" ");
              System.out.println(classes);

  • Javascript array help needed to generate narrative from checkboxes

    For context...  the user will indicate symptoms in cardiovascular section, selecting "deny all", if none of the symptoms apply.  The narrative sub-form needs to processes diagnosis sub-form and generate text that explains the symptoms in a narrative form.  For example, if the user selects "deny all" in the cardiovascular section, the Cardiovascular System Review field would have:  "The patient denies:  High Blood Pressure, Low Blood Pressure.  The logic associated with the narrative needs to account for "deny all" and all the variations of selections.
    I have what I think is a pretty good start on the logic, but would like some help with the following:
    1) loading selected fields into the cv_1s array
    2) loading fields not selected into the cv_0s array
    3) generating the narrative
    See "phr.narrative.cv_nar::calculate - (JavaScript, client)" for the coding I've done thus far.  Feel free to comment on any efficiency opportunities you see.  I have a SAS programming background, but I'm new to Javascript.  Thanks...
    Rob

    Hi Rob,
    One approach would be to give your checkboxes the same name so they can then be referenced as a group and use the caption as the source of your text, so you shouldn't have to duplicate the text and will make it easier to add more later.
    Attached is a sample doing that.
    Hope it helps.
    Bruce

  • Array help needed!!!

    import java.lang.String;
    import java.io.*;
    import java.io.IOException;
    import java.util.*;
    import java.lang.Boolean;
    class Books
    public static final int SIZE=3;
    // public static final int LOAN;
    // public static final int RETURN;
    //public static final int QUERY;
    static int option;
    String title;
    String author;
    boolean loanStatus;
    String borrowerID;
    Date loanDate;
    Date dueDate;
    Books[]p0=new Books[SIZE];
    static void DisplayMenu()
    System.out.println("===Menu===");
    System.out.println("0 to Exit");
    System.out.println("1 to Borrow a book");
    System.out.println("2 to Return a book");
    System.out.println("3 to Query a book");
    System.out.print("===Your Choice>>");
    public static void main(String[] args)
    throws IOException
    BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    String string;
    Books display =new Books();
    do
    System.out.println("\n\n");
    Date loanDate = new Date();
    Date dueDate = new Date();
    dueDate.setTime(loanDate.getTime() + (long)(24*60*60*1000)*14);
    System.out.println(loanDate);
    System.out.println(dueDate);
    display.DisplayMenu();
    System.out.flush();
    string=stdin.readLine();
    option=Integer.parseInt(string);
    switch(option)
    case 0:
    System.out.println("Exit");
    break;
    case 1:
    //display.displayBookList(Books[] p0)
    display.displayBookList(p0);
    display.loanBook();
    break;
    case 2:
    display.returnBook();
    break;
    }while(option!=0);
    void loanBook() throws IOException {
    BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    String string;
    if(!loanStatus){
    System.out.println("Enter borrower ID: ");
    System.out.flush();
    borrowerID=stdin.readLine();
    loanStatus=true;
    else
    System.out.println("Book is on loan");
    public void Books()
    // Books[]p0=new Books[SIZE];
         loanStatus=false;      
    p0[0]=new Books();
    p0[0].title="Java Software Solution";
    p0[0].author="Lewis Loftus";
    p0[1]=new Books();
    p0[1].title="Java How To Programming";
    p0[1].author="Lewis Loftus";
    p0[2]=new Books();
    p0[2].title="Java";
    p0[2].author="Lewis Loftus";
    void returnBook()
    if( loanStatus)
    loanStatus=false;
    System.out.println("Book is return");
    else
    System.out.println("Book is Not on loan");
    static void displayBookList(Books[] p0)
    //Books display=new Books();
    System.out.println("===Book List===");
    System.out.println("0 Back To Main Menu");
    System.out.println("1 "+p0[0].title);
    System.out.println("2 "+p0[1].title);
    System.out.println("3 "+p0[2].title);
    System.out.print("===Your Choice>>");
    static void processBook(Books[] p0) throws IOException
    System.out.flush();
    string=stdin.readLine();
    option=Integer.parseInt(string);
    switch(option)
    case 0:
    display.DisplayMenu();
    break;
    case 1:
    break;
    case 2:
    display.returnBook();
    break;
    Does anyone know how why i cant access the array???

    Hello,
    After u make p0 as display.p0 inside choice 1 in your main method u can compile the code.
    But still there are some problems in ur code.
    1)when u will try running it and give option as 1.
    ur constructor --- public void Books() will not be called because its not a constructor at all its a method. In any case a constructor can not have a return type.
    if u give a return type to a constructor as given void by u.then that constructor wil be treated as a method and when u costruct the objects default costructor will be called. So ur constructor is never called.Thats why it will
    give u null pointer exception when u try to display the list of books.
    2) if u remove void from ur constructor...
    then also u are calling new Books() constructor again in side new Books() constructor, so it will go in to an infinite loop....
    so be clear what u want to do and then proceed..
    hope this will be of help.
    Amrainder

Maybe you are looking for

  • Install new hardware and update imac g3  os 9.2 to os 10 or get a pc

    My dad owns an IMAC g-3 year (2000 or 2001) running os 9.2 that wont run his new scanner--"requires 10.1 os or later". He is also not able to install the DSL modem program from Verizon as it also requires "10.1 mac os or later" to install---so he can

  • Use Time Machine on ONLY one specific folder?

    I wish to use the Time Machine function to backup only one specific folder on my computer, the DROPBOX folder. How can I implement this and inform Time Machine of my choice? According to my first investigations, I only have the choice to select folde

  • Working with previous version of FCP

    Please excuse me if this has been recently answered, as my computer has been stalling a lot as I search for an answer (that twirling thing going around and around) and I need some feedback as soon as I can. I have to make a trailer within the next mo

  • How do i attach a photo to an email without it appearing as a whole photo on the page

    When I try to attach a photo from  iPhoto to an email, the whole photo shows on the page and I cant seem to be able to attach it as an attachment. 

  • Execution time of a report as a column

    Hi Gurus, Normally if you want to know the report execution time we will go to the Administrator-->manage sessions there we will find the time of execution of the respective reports. Is it possible to add column(Execution Time) in the report and it a