Please try the below one: Type the code in Developer Console and Exceute It
Factorial program:
public class sample { public void fact(Integer n) { long ans = 1; if (n < 0) { System.debug('No negative numbers'); } else { for (Integer i = 1; i <= n; i++) { ans *= i; } } System.debug(ans);
} }
Press Ctrl+E and Type it
sample s=new sample(); s.fact(5);
Please Mark As a Best Answer.. If it was helpul to you..
Please try the below one: Type the code in Developer Console and Exceute It
Factorial program:
public class sample { public void fact(Integer n) { long ans = 1; if (n < 0) { System.debug('No negative numbers'); } else { for (Integer i = 1; i <= n; i++) { ans *= i; } } System.debug(ans);
} }
Press Ctrl+E and Type it
sample s=new sample(); s.fact(5);
Please Mark As a Best Answer.. If it was helpul to you..
Please try the below one:
Type the code in Developer Console and Exceute It
Factorial program:
public class sample
{
public void fact(Integer n)
{
long ans = 1;
if (n < 0) {
System.debug('No negative numbers');
}
else
{
for (Integer i = 1; i <= n; i++) {
ans *= i;
}
}
System.debug(ans);
}
}
Press Ctrl+E and Type it
sample s=new sample();
s.fact(5);
Please Mark As a Best Answer.. If it was helpul to you..
Thanks & Regards,
Syed Jabeena
All Answers
You can use the code from https://salesforceforfresher.wordpress.com/2021/06/13/factorial-salesforce-apex-trigger/
Also see related post: https://developer.salesforce.com/forums/?id=9060G0000005ZujQAE
Some basic code snippets: https://webkul.com/blog/apex-programming-basics/
If this information helps, please mark the answer as best. Thank you
Please try the below one:
Type the code in Developer Console and Exceute It
Factorial program:
public class sample
{
public void fact(Integer n)
{
long ans = 1;
if (n < 0) {
System.debug('No negative numbers');
}
else
{
for (Integer i = 1; i <= n; i++) {
ans *= i;
}
}
System.debug(ans);
}
}
Press Ctrl+E and Type it
sample s=new sample();
s.fact(5);
Please Mark As a Best Answer.. If it was helpul to you..
Thanks & Regards,
Syed Jabeena