Menu Close

Number divisible by 11 or not!! [Java] ..FTC

Given a number (n) , the task is to find if its divisible by 11 or not.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an number x.

Output:
For each test case in a new line print 1 if n is divisible by 11 else print 0.

TestCases: 2

Input: n = 76945
Output: 1

Input: n = 12462
Output: 0
import java.io.*;
import java.util.*;
public class temp {
  public static void main(String[] args) {
    int n;
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter the no: of testcases:  ");
    n = scan.nextInt();
    
    List<Integer> arraylist = new ArrayList<Integer>();
    
    System.out.println("Enter the numbers:  ");
    for(int i=0;i<n;i++){
      arraylist.add(scan.nextInt());
    }
    
    for (int ele : arraylist){
      if(ele % 11 == 0){
        System.out.println("1 - Yes, its divisble by 11");
      }
      else{
        System.out.println("0 - No, its not divisble by 11");
      }
    }
  }
}

INPUT_1:
Enter the no: of testcases:
2
Enter the numbers:
76945
12462

OUTPUT:
1 – Yes, its divisible by 11
0 – No, its not divisible by 11


INPUT_2:
Enter the no: of testcases:
2
Enter the numbers:
1111
56891

OUTPUT:
1 – Yes, its divisible by 11
0 – No, its not divisible by 11


INPUT_3:
Enter the no: of testcases:
3
Enter the numbers:
4589
5421
144

OUTPUT:
0 – No, its not divisible by 11
0 – No, its not divisible by 11
0 – No, its not divisible by 11


INPUT_4:
Enter the no: of testcases:
1
Enter the numbers:
121

OUTPUT:
1 – Yes, its divisble by 11


INPUT_5:
Enter the no: of testcases:
4
Enter the numbers:
1211
132
220
363

OUTPUT:
0 – No, its not divisible by 11
1 – Yes, its divisible by 11
1 – Yes, its divisible by 11
1 – Yes, its divisible by 11


ILLUSTRATION:

Executed using javac in linux terminal