|
-
July 27th, 2002, 09:13 PM
#1
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");
}
}
-
July 28th, 2002, 06:09 AM
#2
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
instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|