nagchiru Posted November 27, 2010 Report Share Posted November 27, 2010 Hello experts, I need to check if a particular range of numbers falls in a given range of numbers. For example I need to check if 10 to 20 falls in range of 1 to 100, the program should return "inRange" in this case, if the ranges are overlapping the program needs to indicated the same ex: 50 to 150 overlaps with 1 to 100 range.Please help me to write this java program. Quote Link to comment Share on other sites More sharing options...
rk_theprince Posted November 27, 2010 Report Share Posted November 27, 2010 vammooo..Java naaa[img]http://i325.photobucket.com/albums/k379/NFDB/All%20Comedians%20-%20Male/th_oc1.gif[/img] Quote Link to comment Share on other sites More sharing options...
kotha thread Posted November 27, 2010 Report Share Posted November 27, 2010 int intiailValue=10,finalValue=50 or try some other value;for(i=intialValue;i<=finalValue;i++){if(i>100){s.o.p("RESULT:"+intialvalue+"to"+(i-1)+"are in the range and from "+i+"to "+finalValue+" are out of range"); break;}}if(finalValue<=100){sop("in range")this is a small idea u can improvize it Quote Link to comment Share on other sites More sharing options...
OnlyKufleesNoJefdas Posted November 27, 2010 Report Share Posted November 27, 2010 public class InRange { public static void main(String args[]){ int min = 1; int max = 100; int checkMin = 10; int checkMax = 20; if((checkMin < min && checkMax < min) || (checkMin > max && checkMax > max)){ System.out.println("Out of Range"); } if(checkMin < min && checkMax > min){ System.out.println("Overlapping range"); int overlap = checkMax - min; System.out.println("Number of numbers overlapping "+overlap); System.out.println("Overlapping range :" +min+ " - "+checkMax); } if(checkMin > min && checkMax < max){ System.out.println("InRange"); } if(checkMin > min && checkMax > max){ System.out.println("Overlapping range"); int overlap = max - checkMin; System.out.println("Number of numbers overlapping "+overlap); System.out.println("Overlapping range :" +checkMin+ " - "+max); } if(checkMin < min && checkMax > max){ System.out.println("Overlapping range"); int overlap = max - min; System.out.println("Number of numbers overlapping "+overlap); System.out.println("Overlapping range :" +min+ " - "+max); } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.