You need to sign in to do that
Don't have an account?
palli
Even numbers printing 1 to 50 in developer console
hi,
how print even numbers between 1 to 50 in developer console class......
i write a code here ...........
An error is generate ... line9:18 no aviable alternaive at character '%'...
class
================
public class ListEvenNumbers
{
public void evenMethod()
{
Integer limit=50;
System.debug('Printing even numbers between 1 and '+limit);
for(Integer i=1;i<=limit;i++)
{
if(i%2==0)
{
System.debug('Display the even numbers'+i);
}
}
}
}
please help me
Limit is a salesforce keyword.
Replace limit with some other variable.
All Answers
You don't have the '%' operator for mod in Apex, you have to use Math.mod, e.g.
hi now here an error ,
expecting a semo colon,found "limit"
Integer limit=50;
please help me
You might have missed some semi colon or braces issue. Can you post your code??
public class ListEvenNumbers
{
public void evenMethod()
{
integer limit=50;
System.debug('Printing even numbers between 1 and '+limit);
for(Integer i=1;i<=limit;i++)
{
if (0==math.mod(i, 2))
{
System.debug('Display the even numbers'+i);
}
}
}
}
Limit is a salesforce keyword.
Replace limit with some other variable.
tHANK U VERY MUCH............