NZEC in java

This is the first ever programmer i have tried in java.after learning basics… But i am getting error saying that NZEC.Then i found out that this was related to return type or other return problem…can anyone help me in removing this error.i have written the code below.plz give me a immediate reply\

**

import java.util.Scanner;
class Codechef
{
public static void main (String[] args)
{
int ctr; int n;double a[]=new double[20];

    Scanner input=new Scanner(System.in);
    n=input.nextInt();
    
    
    for(int i=0;i<n;i++)
{ ctr=0;
     a[i]=input.nextInt();
       while(a[i]>0)
       {if(a[i]%10==4)ctr++;
       a[i]/=10;
       }
       System.out.println(ctr);
}
       
       
       

}
}

**

plz reply fast guys

What is the question??

Always provide the problem link while asking for a doubt.

There are two problems in your code:

  1. According to the constraints, 1 <= T <= 10^{5}, but you have declared your array to be of size 20. So, change the size of the array to 10^{5}.
  2. The data type of your array is double, but you are trying to get the last digit of the number by taking the mod and dividing it by 10. This method works only with integers, not with floating-point value. So, change the data type of the array to int.

After doing these changes, your code will work fine.

EDIT1: Here is the corrected code https://www.codechef.com/viewsolution/14682883

CAN u change the code and sent.bz i have tried it is not working.plz do it fast

I’ve updated the answer and added the code.

thnks a lot

import java.util.*;
class TestClass {
public static void main(String args[] ){
Scanner s = new Scanner(System.in);
int c = s.nextInt();
s.nextLine();

        while(c-->0){
            int count=0;
            String c1 = s.nextLine();
            for (int i=0;i<c1.length() ;i++ ) {
                if(c1.charAt(i) == '4'){
                    count++;
                }
            }
            System.out.println(count);
        }      
    }
}

Hey, you don’t need to award any points. By this, you are losing your karma. You can rather upvote and accept an answer. This way, you will gain karma points and still be grateful.

1 Like

Please refrain from using award point feature of forum for accepting answer. Just click on that “tick in circle” below “thumbs down button” to accept his answer and grant him the deserved karma. :slight_smile: