samedi 19 octobre 2019

Why does using if-else condition give me an NZEC error in this?

I have been receiving the NZEC error in this code. I have to return x if the integer is divisible by 4 and x-1 if otherwise.

I have tried the Scanner function to get my input value and the sout functions alongside if-else functions to set my conditions.

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

import java.util.Scanner;
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
    {

        System.out.println("Enter your number");
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        if (x%4==0) {
            System.out.println(x);
        }
        else
        {
            System.out.println(x-1);
         }
}
}

NZEC error received.

Aucun commentaire:

Enregistrer un commentaire