Posts

Playing with mobile numbers

Given  an number.  The task is to tell whether the number is  valid   indian  mobile number or not. Print "Valid" if it is a valid  indian  mobile number, otherwise print "Invalid".  Rules for valid  :- indian  mobile  number The number should contain 10 or 11 or 12 digits. If it contains 10 digits, then  first   digit  should be 7 or 8 or 9. If it contains 11 digits, then  first   digit  should be 0 and second rule  follwed . If it contains 12 digits, then first two digits should be 91 and second rule  followed . Input:  The first line contains a single integer T i.e. the number of test cases. Each test case contains a single number(N) in string representing a mobile number  Output: Corresponding to each test case, print "Valid"  if  inumber  is valid  indian  mobile number otherwise  printf  "Invalid" on a new line. Constraints: 1<=T<=20 10<=  |N| <= 12 here |N| denotes the size of number string. Example:

For a given N, prints the sum of even and odd integers of the first N natural numbers.

First line of the input contains an integer T which denotes the number of test cases. Then T test cases follow.  Each test case contains a single line containing N. Output:  For each test case, print space separated sums of even and odd integers of the first N natural numbers respectively. Constraints: 1 <= T< = 200 1<=N<=10000 Example: Input: 2 1 6  Output: 0 1 12 9    CODE: import java.util.*; import java.lang.*; import java.io.*; class GFG  { public static void main (String[] args)  { //code Scanner sc= new Scanner(System.in); int n=sc.nextInt(); while(n>0) {     int i,natural_num,even=0,odd=0;     natural_num=sc.nextInt();         for(i=1;i<=natural_num;i++)         {             if(i%2==0)                 even+=i;             else                 odd+=i;         }            System.out.println(even+" "+odd);         n--; } } }