+ Start a Discussion
Syed Noormohamad 14Syed Noormohamad 14 

Error: Compile Error: line 6:20 no viable alternative at character '%' at line 6 column 20

public class PrimeNo
{
    public static void m1(integer n)
    {
     boolean flag=true;
     integer input=n%i;
     for(integer i=2 ;i<=n;i++){
      if(input==0){
      Sytem.debug('the given number is not a prime number'+n);
      flag=false;
      break;
      }
      
      }
      if(flag==true){
      sytem.debug('the value is prime no'+n);
     }
    
    }

}
brahmaji tammanabrahmaji tammana

Hi Syed,

No such operator (%) exist in Apex.
Use Math class to get the remainder.

Thanks

Brahma

Syed Noormohamad 14Syed Noormohamad 14


Error: Compile Error: Variable does not exist: Sytem at line 11 column 7

public class PrimeNo
{
    public static void m1(integer n)
    {
     
     boolean flag=true;
         

     for(integer i=2 ;i<=n;i++){
      if(math.mod(n,i)==0){
      Sytem.debug('the given number is not a prime number'+n);
      flag=false;
      break;
      }
      
      }
      if(flag==true){
      sytem.debug('the value is prime no'+n);
     }
    
    }


what could my Error . unable to under stand