function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sreenivas_cippyalisreenivas_cippyali 

prime numbers: Error: Compile Error: line 15:8 no viable alternative at character '%' at line 15

public class prime
{
public void m1(integer a)
{
integer n,i,s,c;

 

for(n=1;n<=a;n++)
{
c=0;
for(i=1;i<=n;i++)
{
s=0;
s=n%i;
if(s==0)
{
c++;
}
}

if(c==2)
{
System.debug('---------------->'+n);
}
 }
}
}

SFDC_EvolveSFDC_Evolve

At the line number 15 

 

Instead of 

s=n%i;

if(s==0)

 

Please use this . . 

 

s = Math.Mod(n,1);

if (s == 0)

 

Please mark this as solution if it solves the issue ..  

 

Thanks 

SFDC_Evolve

SFDC_EvolveSFDC_Evolve

Sorry ... It wass  i not 1

 

s = Math.Mod(n,i);