ilovelinux2006
Programmer
Hey everyone,
Ive been working on this for hours!
I have three variables: a, b, c
I am suppose to use a.compareTo(b)
Here is the function:
public int compareTo(Number t){
if(t.getNumber() > this.getNumber()){
return 1;
}else if(t.getNumber() < this.getNumber()){
return -1;
}else{
return 0;
}
}
I have been working many many many hours on trying to get the middle number!!!!!!!!!! I found how to get the two largest and smallest numbers with the compareTo() function:
// Returns the smallest of the 3 Numbers:
if(b.compareTo(a) <= 0 && c.compareTo(a) <=0){
System.out.print(a);
}else if(a.compareTo(b) <=0 && c.compareTo(b) <=0){
System.out.print(b);
}else{
System.out.print(c);
}
// Returns the largest of the 3 Numbers: (I just changed the < to >)
if(b.compareTo(a) >= 0 && c.compareTo(a) >=0){
System.out.print(a);
}else if(a.compareTo(b) >=0 && c.compareTo(b) >=0){
System.out.print(b);
}else{
System.out.print(c);
}
Please help me, this is making me go crazy!
Ive been working on this for hours!
I have three variables: a, b, c
I am suppose to use a.compareTo(b)
Here is the function:
public int compareTo(Number t){
if(t.getNumber() > this.getNumber()){
return 1;
}else if(t.getNumber() < this.getNumber()){
return -1;
}else{
return 0;
}
}
I have been working many many many hours on trying to get the middle number!!!!!!!!!! I found how to get the two largest and smallest numbers with the compareTo() function:
// Returns the smallest of the 3 Numbers:
if(b.compareTo(a) <= 0 && c.compareTo(a) <=0){
System.out.print(a);
}else if(a.compareTo(b) <=0 && c.compareTo(b) <=0){
System.out.print(b);
}else{
System.out.print(c);
}
// Returns the largest of the 3 Numbers: (I just changed the < to >)
if(b.compareTo(a) >= 0 && c.compareTo(a) >=0){
System.out.print(a);
}else if(a.compareTo(b) >=0 && c.compareTo(b) >=0){
System.out.print(b);
}else{
System.out.print(c);
}
Please help me, this is making me go crazy!