Saturday, April 29, 2017

URI Online Judge Solution - 1866 Bill in java language

Solution - URI Online Judge Solution - 1866 Bill in java


URI Online Judge | 1866

Bill

By Ricardo Martins, IFSULDEMINAS BR Brazil
Timelimit: 1
Two friends ask the attendant a snack bar propose a challenge , so that whoever hit him more , would not pay the bill. Then the following is proposed : Given the following sum below report the result , with the same number of terms : S = 1 - 1 + 1 - 1 + 1 - 1 + 1 - 1 ... Write a program that , given a number of terms, report the result of the sum above.

Input

An integer C shall be informed , which is the amount of test cases. Each test case starts with an integer N ( 1 ≤ N ≤ 1000) , indicating the number of terms of the sum .

Output

For each test case print a number S , which is the sum of N terms of expression.
Input SampleOutput Sample
3
11
7
18
1
1
0

Solution - URI Online Judge Solution - 1866 Bill in java

import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int n = in.nextInt(), x;

  for (int i = 0; i < n; i++) {
   x = in.nextInt();
   if(x % 2 == 0) System.out.println(0);
   else System.out.println(1);
  }
 }
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.