Day 1 Assignment (Series)
Nov28

Day 1 Assignment (Series)

I am back once again with lots of Salesforce programming practice questions for beginners. I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the first day assignment of creating various series using Salesforce Apex language. Writing down scripts on Execute anonymous we can produce the following series. New developers with little or no knowledge of programming can start their practice from these questions. 1. Write a program in developer console / execute anonymous to print a Series which produce Output like this (1 , 4 , 8 , 32 , 64 , 256 , 512 , …..);  For Loop in Salesforce.   Click here to learn more  public with sharing class Series { public integer display(integer userInput) { integer i = 1; system.debug(i); for(integer a=1 ; a<=userInput ; a++) { if(math.mod(a,2)==0) { i=i*2; } else { i=i*4; } system.debug(i); } return i; } } 2 .Print a Series which produce Output like this(1.3 , 1.31 , 1.313 , 1.3131 , 1.31313 , …..);  Salesforce Math class functions.   Click here to learn more public with sharing class Series2 { public Series2(integer num) { double d = 1.0; for(integer i =1;i<=num;i++) { if(math.mod(i,2)==0) { d=d+math.pow(10,-i); } else { d=d+(3*(math.pow(10,-i))); } system.debug(d); } } }   3.Print all the Factors of a number. Example input: 84  Output: Factors (2 , 3 , 4 , 6, 7, 12,14 , 21,28, 42);   Click here to learn more public with sharing class Series3 { public Series3(integer num) { for(integer i =2;i<=num;i++) { if(math.mod(num,i)==0) { system.debug(i); } } } }   4.Print a Series which produce Output like this(522 , 502 , 492 , 472 , 462 , 442 , …);   Click here to learn more public with sharing class Series5 { public integer display(integer userinput) { integer i = 522; system.debug(i); for(integer a=1 ; a<=userInput ; a++) { if(math.mod(a,2)==0) { i=i-10; } else { i=i-20; } system.debug(i); } return i; } }   5. Take any number and print its Units, Tens, Hundreds, Thousand etc. Example input: 293,023 Output like this : 200,000, 90,000, 3,000, 0, 20, 3   Click here to learn more public with sharing class Units { public void show(integer n) { integer val=1; while(n>0){ integer temp=math.mod(n,10); n=n/10; temp=temp*val; system.debug(‘temp is’+temp); val=val*10; } } }   6. Take any number and print its Units, Tens, hundreds, thousand etc both in decimal and integer part. Example input: 293.065. Output: 200.0, 90.0, 3.0, 0.0, 0.06, 0 .005   Click here to learn more public with sharing class UnitPlacesOfDecimalNumber { public void showNumbers(Decimal originalNumber) { Decimal num = originalNumber; //To Seperate Integer Part and Decimal Part of the number.(Like 293.065 -> 293 and .065) Integer intPartOfNumber = (Integer) num; Decimal decPartOfNumber = num – intPartOfNumber; List<Integer> intNumbersList = new List<Integer>(); //To get List of Integer Part.(Like 293 -> 3,...

Read More