Maximize result of bitwise AND
I think your code is difficult to read/understand because of:


Inexpressive or confusing naming
Lack of any documentation
Confusing indentation and spacing. Consider using an online code beautifier 


Let's start from the top.




int T = in.nextInt();
int k[] = new int [T];
int n[]  = new int [T];
for(int  i= 0;i&lt;T;i++){
 n[i] = in.nextInt();
 k[i]=in.nextInt();
}



Mathematical notation doesn't necessarily translate very well to code, where mathematical notation is meant to represent complex concepts in short form, code is meant to be concrete applications of concepts in a way that computers can process, and humans can hopefully understand. 

I did a bit of renaming to make these clearer. Note that using underscore_case is not typical for Java naming, but I think casesN or nCases didn't read well at all.

int numCases = in.nextInt();
int[] cases_N = new int[numCases];
int[] cases_K = new int[numCases];
// Populate the cases from STDIN
for (int i = 0; i &lt; numCases; i++) {
    cases_N[i] = in.nextInt();
    cases_K[i] = in.nextInt();
}




This for loop's iterator naming is misleading:


for(int karr =0 , narr=0;karr&lt;k.length&amp;&amp; narr&lt;n.length;karr++,narr++)



In reality, karr and narr are not arrays, so let's not call them arr. Furthermore, since they are always only ever incremented together, and you already know you'll have exactly the same number of \$K\$ and \$N\$ cases, there's really no point in having both. 

Also, you already have a value \$T\$ (or numCases) so there is no need to get the length of the arrays. 

for (int caseNum = 0; caseNum &lt; numCases; caseNum++)


I also replaced each other occurrence of those two variables with caseNum.



This kind of reference is used a lot inside that big loop: cases_N[caseNum] and cases_K[caseNum]. Now would be a good time to just declare N and K with those values.

This makes the next section make more sense:


int N = cases_N[caseNum];
int K = cases_K[caseNum];
int a[] = new int[N];
for (int i = 0; i &lt; N; i++) {
    a[i] = i + 1;
}



Now we can give this a array a meaningful name: intsUpToN

int[] intsUpToN = new int[N];
for (int i = 0; i &lt; N; i++) {
    intsUpToN[i] = i + 1;
}


We can also replace the two instances of intsUpToN.length, since that value is already known (it's the current N value) and we are not adding or removing anything from the array. 



The code is already much easier to understand now. I added little snippets of code comments to make it more clear. I also combined the last two if checks into one with &amp;&amp;. 

I removed temp because it is assigned the value of max and never used for anything except comparison, so we can just use max in the comparison instead.

Note that I did not address the algorithm, as algorithms are not my forte. It is clearly a brute force algorithm, and chances are someone who is good with mathematics can suggest a more efficient algorithm. 

The resulting code passes all tests cases.

public class Solution {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int numCases = in.nextInt();
        int[] cases_N = new int[numCases];
        int[] cases_K = new int[numCases];
        // Populate the cases from STDIN
        for (int i = 0; i &lt; numCases; i++) {
            cases_N[i] = in.nextInt();
            cases_K[i] = in.nextInt();
        }
        // Outer loop for each case
        for (int caseNum = 0; caseNum &lt; numCases; caseNum++) {
            int N = cases_N[caseNum];
            int K = cases_K[caseNum];
            // Fill in array integers from 1 to N
            int[] intsUpToN = new int[N];
            for (int i = 0; i &lt; N; i++) {
                intsUpToN[i] = i + 1;
            }
            // Brute force method to logically "AND" all possible values,
            // returning with the maximum "AND" result at the end
            int max = 0;
            int andValue = 0;
            for (int i = 0; i &lt; N; i++) {
                for (int j = 1; j &lt; N; j++) {
                    if (intsUpToN[i] &lt; intsUpToN[j]) {
                        // This is the logical "AND" calculation
                        andValue = intsUpToN[i] &amp; intsUpToN[j];
                        if (andValue &lt; K &amp;&amp; andValue &gt; max) {
                            max = andValue;
                        }
                    }
                }
            }
            System.out.println(max);
        }
    }
}