Question

I have 1 string which has to be between a specific range.

The range of the values are: "620/75R38" - "1050/50R38" as you guys can see, it should fit within the range. Yet i don't know how to put this in java code who can help me? I tried already with String.compareTo() function but somehow it doesn't give the right answeres.

EDIT

Here is what i've already tried.

private subMaat = "";
private maat = "650/65R38";
if(maat.contains("R")){
        subMaat = maat.substring(0, maat.lastIndexOf("R"));
    } else if (maat.contains("-")){
        subMaat = maat.substring(0, maat.lastIndexOf("-"));
    }

if(subMaat.compareTo("620/75") >= 0 && subMaat.compareTo("1050/50") <= 0){
   //do something
}
Était-ce utile?

La solution

Try this

   String lower="620/75R38";
   String upper= "1050/50R38";

   String str="50/65R38";


   if(str.compareTo(lower)>0 && upper.compareTo(str)<0){
       System.out.println("inside the range");
   }

Autres conseils

How to check if an integer is in a given range? and compare both sizes like this:

 if ((size1[1] > 650 && size2[1]< 1050) && (size1[2] > 50 && size2[2]< 75)) { then }

Or you could put all the sizes in an ArrayList, given it's not that big (I guess these sizes are for tires?)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top