CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    4

    CompareTo Integers

    How do i compare 2 integers this is the code i'm writing

    int w1 = tempNum.compareTo(time);

    the complie error says : int cannot be derefferrenced

    The code is listed below ; Please reply ASAP

    public void add(String j, String p){

    int time = Integer.parseInt(p);

    //System.out.println(size());

    if (size() ==0){


    v.addElement(j+"$"+p);



    }else if(size() == numAppointments){

    System.out.println(numAppointments);
    System.out.println("DateBook is Full");
    }
    else {

    int w = size();
    for(int i=0; i<=w;i++){
    String tempElement = get(i); //Getting the Element
    int w1 = tempElement.indexOf("$"); // Looking for the index to sort

    String tempNumber = tempElement.substring(w1+1,w1+2); // Extracting out the number

    int tempNum = Integer.parseInt(tempNumber); // Converting it into an int

    int num1 = tempNum.compareTo(time); //Comparing them
    if(num1<0){
    v.add(i,j+"$"+p);
    }
    else if(num1==0){
    v.add(i,j+"$"+p);
    }
    else {
    v.add(i+1,j+"$"+p);
    }
    }
    System.out.println("Dumb");
    }
    }

  2. #2
    Join Date
    Jan 2001
    Location
    Germany
    Posts
    222
    int num1 = tempNum.compareTo(time);
    tempNum is an int, a primitive type that doesn't have any methods. Tha line is completely wrong. So something like
    if (tempNum < time)
    instead.
    Teamwork Software - Stuff That Does Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured