FUNCTIONS

11. Write a Java method that accepts three integers and checks whether they are consecutive or not. Returns true or false.

            class ConsecutiveNumber
            {
                static int findMin(int num1,int num2,int num3)
                {
                   int min=num1;
                        if(num2<min)  
                         {
                             min= num2;
                          }
                   if(num3<min) 
                        {
                            min= num3;
                         }
                 return min;
            }
            static int findMax(int num1,int num2,int num3)
                {
                   int max=num1;
                        if(num2>max)  
                         {
                             max= num2;
                          }
                   if(num3>max) 
                        {
                            max= num3;
                         }
                 return max;
            }
            
                 static Boolean checkConsecutiveNumber(int num1,int num2,int num3)
                  {
                            int min = findMin(num1, num2, num3);
                           int max = findMax(num1, num2, num3);
                       return (max - min ==2) && (num1+num2+num3== max + min+(min+1));
            }
            public static void main(String st[])
             {
                System.out.println("Are 4,5 ,6 consecutive:\n" + checkConsecutiveNumber(4, 5, 6)); 
                    System.out.println("Are 10,11,13 consecutive:\n" +checkConsecutiveNumber(10, 11, 13));
            }
            }
                      
            
        

OUTPUT

            Are 4,5 ,6 consecutive:
            true
            Are 10,11,13 consecutive:
            false