Decrement OR Increment Solution

Problem

Write a program to obtain a number N and increment its value by 1 if the number is divisible by 4 otherwise decrement its value by 1.

Input:

  • First line will contain a number N.

Output:

Output a single line, the new value of the number.

Constraints

  • 0 \leq N \leq 1000

Sample Input:

5

Sample Output:

4
### EXPLANATION:

Since 5 is not divisible by 4 hence, its value is decreased by 1.




Program :

 /* package codechef; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Codechef

{

    public static void main (String[] args) throws java.lang.Exception

    {

        // your code goes here

        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();

        if(n%4==0)

        n+=1;

        else

        n-=1;

        System.out.println(n);

    }

}

Post a Comment

0 Comments