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
Kumar__MayankKumar__Mayank 

How can I see complete prime numbers between 1 and 100 in LOG?

integer i=0;
integer num=0;

while( i <= 100)

    //system.debug('here' + i);
    integer counter=0;
    for (num = i ;num >= 1; num--)
    {
        if(math.mod(i,num)==0)
        {
            counter=counter+1;
        }
    }
    if (counter == 2)
    {
        system.debug(i);
    }
   i++;     
}

Above code I am running in anonymous window to get prime numbers between 1 to 100. But when I go for Debug Only it shows like this:
User-added image

Any body can tell me how to get complete prime numbers here?
 
Ankit SehgalAnkit Sehgal
Integer i =0;
Integer num =0;
       //Empty String
String  primeNumbers = '';

for (i = 1; i <= 100; i++)         
{ 		  	  
	Integer counter=0; 	  
	for(num =i; num>=1; num--)
	{
		if(Math.mod(i,num)==0)
	     {
			counter = counter + 1;
	     }
	 }
	 if (counter==2)
	 {
		primeNumbers = primeNumbers + i + ' ';
	 }	
   
}	
System.debug(primeNumbers);

I hope this helps
Kumar__MayankKumar__Mayank
Thanks ....but my question is not that 1........see the debug results.....my code is correct...it will give prime numbers between 1 to 100 with every prime number in new line( I dont want all prime numbers in one string)......but in debug only its starting from 53 ....It should be started from 2....So,please tell me this reason....