 ShowAll Questionssorted byDate Posted srujith chintha 4

# print all of the positive integer from 1 to 100

• Print out all positive integers from 1 to 100, inclusive and in order.
• Print messages to standard output, matching the Sample Output below.
• In the output, state whether each integer is ‘odd’ or ‘even’ in the output.
• If the number is divisible by three, instead of stating that the number is odd or even, state that the number is ‘divisible by three’.
• If the number is divisible by both two and three, instead of saying that the number is odd, even or divisible by three; state that the number is ‘divisible by two and three’.
• Design the logic of the loop to be as efficient as possible, using the minimal number of operations to perform the required logic. Best Answer chosen by srujith chintha 4  Priya (Salesforce Developers) Hey Srujith,

```for(Integer i=1;i<=100;i++){
Integer result = math.mod(i,2);
if(result == 0){
System.debug(i);
}
}```

For more solution, refer this :-
https://developer.salesforce.com/forums/?id=9062I000000gCmpQAE

Thanks  Priya (Salesforce Developers) Hey Srujith,

```for(Integer i=1;i<=100;i++){
Integer result = math.mod(i,2);
if(result == 0){
System.debug(i);
}
}```

For more solution, refer this :-
https://developer.salesforce.com/forums/?id=9062I000000gCmpQAE

Thanks
This was selected as the best answer srujith chintha 4
I have done using this code .but thank u for ur help
public class printIntegers {
public static void printIntegersWithOddOrEven(){
for(integer i=1;i<=100;i++){
if((math.mod(i, 2))==0 && (math.mod(i, 3))==0){
system.debug(i+':is divisible by 2 and 3');
}
else if((math.mod(i, 3))==0){
system.debug(i+': is divisible by  3');
}
else {
if((math.mod(i, 2))==0){
system.debug(i+': is even');
}
else{
system.debug(i+': is odd');
}
}
}
}