Find the integers that doesnot ends with T1 or T2 when squared and added X | Java program to find the integers that ends with either T1 or T2 when squared and added X ; Function to print the elements Not ending with T1 or T2 ; Flag to check if none of the elements Do not end with t1 or t2 ; Traverse through all the elements ; Temporary variable to store the value ; If the last digit is neither t1 nor t2 then ; Print the number ; Set the flag as False ; If none of the elements meets the specification ; Driver Code ; Test case 1 ; Call the function ; Test case 2 ; Call the function
class GFG { static void findIntegers ( int n , int a [ ] , int x , int t1 , int t2 ) { boolean flag = true ; for ( int i = 0 ; i < n ; i ++ ) { int temp = ( int ) Math . pow ( a [ i ] , 2 ) + x ; if ( temp % 10 != t1 && temp % 10 != t2 ) { System . out . print ( temp + " ▁ " ) ; flag = false ; } } if ( flag ) { System . out . println ( ) ; System . out . print ( " - 1" ) ; } } public static void main ( String args [ ] ) { int N = 4 ; int X = 10 ; int T1 = 5 ; int T2 = 6 ; int a [ ] = { 3 , 1 , 4 , 7 } ; findIntegers ( N , a , X , T1 , T2 ) ; N = 4 ; X = 2 ; T1 = 5 ; T2 = 6 ; int b [ ] = { 2 , 18 , 22 , 8 } ; findIntegers ( N , b , X , T1 , T2 ) ; } }